Debian Codegraph @

dateparser_scripts/utils.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import os
2 import shutil
3 from collections import OrderedDict
4
5 from git import Repo
6
7
8 def get_raw_data():
9 cldr_version = "31.0.1"
10 raw_data_directory = "../raw_data"
11
12 cldr_data = {
13 "dates_full": {
14 "url": "https://github.com/unicode-cldr/cldr-dates-full.git",
15 "dir": "{}/cldr_dates_full/".format(raw_data_directory),
16 },
17 "core": {
18 "url": "https://github.com/unicode-cldr/cldr-core.git",
19 "dir": "{}/cldr_core/".format(raw_data_directory),
20 },
21 "rbnf": {
22 "url": "https://github.com/unicode-cldr/cldr-rbnf.git",
23 "dir": "{}/cldr_rbnf/".format(raw_data_directory),
24 },
25 }
26
27 if os.path.isdir(raw_data_directory):
28 # remove current raw data
29 shutil.rmtree(raw_data_directory)
30 os.mkdir(raw_data_directory)
31
32 for name, data in cldr_data.items():
33 print('Clonning "{}" from: {}'.format(name, data["url"]))
34 repo = Repo.clone_from(data["url"], data["dir"], branch="master")
35 repo.git.co(cldr_version)
36
37
38 def get_dict_difference(parent_dict, child_dict):
39 difference_dict = OrderedDict()
40 for key, child_value in child_dict.items():
41 parent_value = parent_dict.get(key)
42 child_specific_value = None
43 if not parent_value:
44 child_specific_value = child_value
45 elif isinstance(child_value, list):
46 child_specific_value = sorted(set(child_value) - set(parent_value))
47 elif isinstance(child_value, dict):
48 child_specific_value = get_dict_difference(parent_value, child_value)
49 elif child_value != parent_value:
50 child_specific_value = child_value
51 if child_specific_value:
52 difference_dict[key] = child_specific_value
53 return difference_dict
54
55
56 def combine_dicts(primary_dict, supplementary_dict):
57 combined_dict = OrderedDict()
58 for key, value in primary_dict.items():
59 if key in supplementary_dict:
60 if isinstance(value, list):
61 combined_dict[key] = value + supplementary_dict[key]
62 elif isinstance(value, dict):
63 combined_dict[key] = combine_dicts(value, supplementary_dict[key])
64 else:
65 combined_dict[key] = supplementary_dict[key]
66 else:
67 combined_dict[key] = primary_dict[key]
68 remaining_keys = [
69 key for key in supplementary_dict.keys() if key not in primary_dict.keys()
70 ]
71 for key in remaining_keys:
72 combined_dict[key] = supplementary_dict[key]
73 return combined_dict