mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-23 07:00:13 +00:00
新增GetTimezonesByLocation接口相关工具和数据,clean code check issues.
Signed-off-by: yeheng <duanyeheng@huawei.com>
This commit is contained in:
parent
b997578f9a
commit
75ede827c4
@ -15,6 +15,8 @@
|
||||
# coding=utf-8
|
||||
#!/usr/bin/env python
|
||||
import re
|
||||
import os
|
||||
import logging
|
||||
import pickle
|
||||
import png
|
||||
|
||||
@ -36,7 +38,7 @@ def read_data(filename):
|
||||
timezones = tz[1:-1].split(",")
|
||||
data_res[location] = timezones
|
||||
|
||||
with open("data/loc2tz.pickle", "wb") as f:
|
||||
with os.fdopen(os.open("data/loc2tz.pickle", os.O_RDWR | os.O_CREAT, 0o640), "wb") as f:
|
||||
pickle.dump(data_res, f)
|
||||
|
||||
return data_res
|
||||
@ -79,19 +81,19 @@ def numerized_dictionary(classes):
|
||||
temp_group[name] = num
|
||||
numerized_classes.append(temp_group)
|
||||
for i, c in enumerate(numerized_classes):
|
||||
print(i)
|
||||
print(c)
|
||||
logging.info(i)
|
||||
logging.info(c)
|
||||
return numerized_classes
|
||||
|
||||
|
||||
def export_numerized_dicts(numerized_classes):
|
||||
with open("data/name2num.txt", "w", encoding="utf-8") as f:
|
||||
with os.fdopen(os.open("data/name2num.txt", os.O_RDWR | os.O_CREAT, 0o640), "w", encoding="utf-8") as f:
|
||||
f.write(str(numerized_classes))
|
||||
num2name_dict_list = []
|
||||
for d in numerized_classes:
|
||||
num2name = dict(zip(d.values(), d.keys()))
|
||||
num2name_dict_list.append(num2name)
|
||||
with open("data/num2name.txt", "w", encoding="utf-8") as f:
|
||||
with os.fdopen(os.open("data/num2name.txt", os.O_RDWR | os.O_CREAT, 0o640), "w", encoding="utf-8") as f:
|
||||
f.write(str(num2name_dict_list))
|
||||
|
||||
|
||||
@ -143,11 +145,11 @@ def save_png_test():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
read_data("data/location2tz.txt")
|
||||
# read_data("data/location2tz.txt")
|
||||
data = load_data("data/loc2tz.pickle")
|
||||
name_classes = classify_timezones(data)
|
||||
nmrzd_classes = numerized_dictionary(name_classes)
|
||||
export_numerized_dicts(nmrzd_classes)
|
||||
t_list = generate_array_from_data(data, nmrzd_classes)
|
||||
map_array = group_in_total(t_list)
|
||||
pack2png(map_array)
|
||||
# pack2png(map_array)
|
Loading…
Reference in New Issue
Block a user