Add helper function
This commit is contained in:
@@ -33,6 +33,28 @@ def create_maps(namelist_fname, key):
|
||||
return names, nums
|
||||
|
||||
|
||||
def create_name_to_lname_map(namelist_fname, key):
|
||||
# Read in the full data dictionary
|
||||
with open(config.name_data_file, 'r') as f:
|
||||
big = json.load(f)
|
||||
|
||||
# Use whitelist to filter data and map only as needed
|
||||
namelist_path = config.namelists_dir / namelist_fname
|
||||
with open(namelist_path, 'r') as f:
|
||||
whitelist = [s.strip() for s in f.readlines()]
|
||||
|
||||
lnames = {}
|
||||
for v in big[key].values():
|
||||
lname = v['localised_name'].strip()
|
||||
name = v['name'].strip()
|
||||
if lname in whitelist:
|
||||
if name in lnames.keys() and lnames[name] != lname:
|
||||
raise Exception(f'Duplicate name {name} for {lname}')
|
||||
lnames[name] = lname
|
||||
|
||||
return lnames
|
||||
|
||||
|
||||
def read_string_data_to_dict(keys):
|
||||
return _read_file_to_dict(config.string_data_file, keys)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user