allow specify geo level of variant
@@ -27,7 +27,7 @@ def read_local_file(file_name): #TODO: how will final file structure look like?
if path_file_name in first_files: #simple list
return [line.strip() for line in file_content[1:]]
- second_files = [path_to_script_files+fi for fi in ["variants.txt", "wrong_regions.txt", "abbreviations.txt", "false_divisions.txt", ] ]
+ second_files = [path_to_script_files+fi for fi in ["wrong_regions.txt", "abbreviations.txt", "false_divisions.txt", ] ]
if path_file_name in second_files: #dictionary, keys seaprated from content with tabs
content = {}
@@ -38,6 +38,22 @@ def read_local_file(file_name): #TODO: how will final file structure look like?
content[l[0]] = l[1]
return content
+ third_files = [path_to_script_files+fi for fi in ["variants.txt"] ]
+
+ if path_file_name in third_files: #need two level-dict
+ content = {}
+ for line in file_content[1:]:
+ l = line.strip().split("\t")
+ if l[0] in content:
+ if l[1] in content[l[0]]:
+ print("Attention, duplicate found while reading " + file_name + ": " + l[0] + " -> " + l[1] + ", " + content[l[0]] + ", " + content[l[1]])
+ content[l[0]][l[1]] = l[2]
+ else:
+ content[l[0]] = {}
+ content[l[0]][l[1]] = l[2]
+ return content
+
+
# Read ordering and lat_longs file and return as dictionary:
def read_geography_file(file_name):
lat_longs = ("lat_longs" in file_name)
@@ -353,8 +369,8 @@ def apply_variants(data): #TODO: currently, the file variants.txt doesn't distin
countries_to_switch = {}
for region in data:
for country in data[region]:
- if country in variants:
- country_correct = variants[country]
+ if country in variants['country']:
+ country_correct = variants['country'][country]
print("Apply variant (country): " + bold(country) + " -> " + bold(country_correct))
countries_to_switch[country] = (region, country_correct)
@@ -364,8 +380,8 @@ def apply_variants(data): #TODO: currently, the file variants.txt doesn't distin
for region in data:
for country in data[region]:
for division in data[region][country]:
- if division in variants:
- division_correct = variants[division]
+ if division in variants['division']:
+ division_correct = variants['division'][division]
print("Apply variant (division): " + bold(division) + " -> " + bold(division_correct))
divisions_to_switch[division] = (region, country, division_correct)
@@ -376,8 +392,8 @@ def apply_variants(data): #TODO: currently, the file variants.txt doesn't distin
for country in data[region]:
for division in data[region][country]:
for location in data[region][country][division]:
- if location in variants:
- location_correct = variants[location]
+ if location in variants['location']:
+ location_correct = variants['location'][location]
print("Apply variant (location): " + bold(location) + " -> " + bold(location_correct))
locations_to_switch[location] = (region, country, division, location_correct)
