Debian Codegraph @

dateparser_scripts/utils.py

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