diff --git a/tools/merge_out.py b/tools/merge_out.py index e6d8bc08..dcab4738 100644 --- a/tools/merge_out.py +++ b/tools/merge_out.py @@ -1,10 +1,9 @@ import json from formatter import per_line_entries -out_ids = [] -out_dupe_ids = [] -out_edited_added_ids = [] -atlas_ids = [] +out_ids = set() +out_dupe_ids = set() +atlas_ids = {} with open('temp_atlas.json', 'r', encoding='utf-8') as out_file: out_json = json.loads(out_file.read()) @@ -12,30 +11,32 @@ with open('../web/atlas.json', 'r', encoding='utf-8') as atlas_file: atlas_json = json.loads(atlas_file.read()) -for entry in atlas_json: - atlas_ids.append(entry['id']) +for i, entry in enumerate(atlas_json): + atlas_ids[entry['id']] = i for entry in out_json: - if (entry['id'] in out_ids): + if entry['id'] in out_ids: print(f"Entry {entry['id']} has duplicates! Please resolve this conflict. This will be excluded from the merge.") - out_dupe_ids.append(entry['id']) - out_ids.append(entry['id']) - + out_dupe_ids.add(entry['id']) + out_ids.add(entry['id']) + for entry in out_json: if entry['id'] in out_dupe_ids: continue if 'edit' in entry and entry['edit']: - index = next((i for i, item in enumerate(atlas_json) if item["id"] == entry['id']), None) + assert entry['id'] in atlas_ids, "Edit failed! ID not found on Atlas." + index = atlas_ids[entry['id']] assert index != None, "Edit failed! ID not found on Atlas." print(f"Edited {atlas_json[index]['id']} with {entry['edit']}") - if 'edit' in entry: - out_edited_added_ids.append(entry['edit']) - del entry['edit'] + del entry['edit'] atlas_json[index] = entry + elif entry['id'] in atlas_ids: + print(f"Edited {entry['id']} manually.") + atlas_json[atlas_ids[entry['id']]] = entry else: print(f"Added {entry['id']}.") atlas_json.append(entry)