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 pathlib import Path
4
5 from git import Repo
6
7
8 CLDR_JSON_DIR = (Path(__file__).parent / "../cldr-json").resolve()
9
10
11 def get_raw_data():
12 cldr_version = "44.1.0"
13 url = "https://github.com/unicode-org/cldr-json.git"
14 if os.path.isdir(CLDR_JSON_DIR):
15 shutil.rmtree(CLDR_JSON_DIR)
16
17 print(f"Clonning {url} @ {cldr_version} on {CLDR_JSON_DIR}...")
18 Repo.clone_from(url, CLDR_JSON_DIR, branch=cldr_version, depth=1)
19
20
21 def get_dict_difference(parent_dict, child_dict):
22 difference_dict = {}
23 for key, child_value in child_dict.items():
24 parent_value = parent_dict.get(key)
25 child_specific_value = None
26 if not parent_value:
27 child_specific_value = child_value
28 elif isinstance(child_value, list):
29 child_specific_value = sorted(set(child_value) - set(parent_value))
30 elif isinstance(child_value, dict):
31 child_specific_value = get_dict_difference(parent_value, child_value)
32 elif child_value != parent_value:
33 child_specific_value = child_value
34 if child_specific_value:
35 difference_dict[key] = child_specific_value
36 return difference_dict
37
38
39 def combine_dicts(primary_dict, supplementary_dict):
40 combined_dict = {}
41 for key, value in primary_dict.items():
42 if key in supplementary_dict:
43 if isinstance(value, list):
44 combined_dict[key] = value + supplementary_dict[key]
45 elif isinstance(value, dict):
46 combined_dict[key] = combine_dicts(value, supplementary_dict[key])
47 else:
48 combined_dict[key] = supplementary_dict[key]
49 else:
50 combined_dict[key] = primary_dict[key]
51 remaining_keys = [
52 key for key in supplementary_dict.keys() if key not in primary_dict.keys()
53 ]
54 for key in remaining_keys:
55 combined_dict[key] = supplementary_dict[key]
56 return combined_dict