mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-11-05 23:29:43 +01:00
978757ce8f
Instead of one temporary JSON file, contributors now can submit patches in form of separate files per entry, that will be merged by `merge_out.py` without dealing with the potential conflicts to the main `atlas.json`.
102 lines
No EOL
2.9 KiB
Python
102 lines
No EOL
2.9 KiB
Python
import json
|
|
import os
|
|
from aformatter import format_all_entries, per_line_entries
|
|
import scale_back
|
|
|
|
from scale_back import ScaleConfig
|
|
|
|
out_ids = []
|
|
atlas_ids = {}
|
|
authors = []
|
|
|
|
with open('../web/all-authors.txt', 'r') as authors_file:
|
|
authors = authors_file.read().strip().split()
|
|
|
|
with open('../web/read_ids.txt', 'r') as ids_file:
|
|
out_ids = ids_file.read().strip().split()
|
|
|
|
with open('../web/atlas.json', 'r', encoding='utf-8') as atlas_file:
|
|
atlas_data = json.loads(atlas_file.read())
|
|
|
|
format_all_entries(atlas_file)
|
|
|
|
base_image_path = os.path.join('..', 'web', '_img', 'canvas', 'place30')
|
|
ScaleConfig.image1 = os.path.join(base_image_path, '159.png')
|
|
scale_back.swap_source_dest('164', '165', os.path.join(base_image_path, '163_159.png'))
|
|
scale_back.scale_back_entries(atlas_file)
|
|
scale_back.swap_source_dest('165', '166', os.path.join(base_image_path, '164_159.png'))
|
|
scale_back.scale_back_entries(atlas_file)
|
|
scale_back.swap_source_dest('166', '167', os.path.join(base_image_path, '165_159.png'))
|
|
scale_back.scale_back_entries(atlas_file)
|
|
|
|
last_id = 0
|
|
|
|
for i, entry in enumerate(atlas_data):
|
|
atlas_ids[entry['id']] = i
|
|
id = entry['id']
|
|
if id.isnumeric() and int(id) > last_id and int(id) - last_id < 100:
|
|
last_id = int(id)
|
|
|
|
patches_dir = "../data/patches/"
|
|
if not os.path.exists(patches_dir):
|
|
print("Patches folder not found. Exiting.")
|
|
exit()
|
|
|
|
for filename in os.listdir(patches_dir):
|
|
f = os.path.join(patches_dir, filename)
|
|
|
|
print(f"{filename}: Processing...")
|
|
|
|
if not os.path.isfile(f) or not f.endswith('json'):
|
|
continue
|
|
|
|
with open(f, 'r', encoding='utf-8') as entry_file:
|
|
entry = json.loads(entry_file.read())
|
|
|
|
if '_reddit_id' in entry:
|
|
reddit_id = entry['_reddit_id']
|
|
if reddit_id in out_ids:
|
|
print(f"{filename}: Submission from {entry['id']} has been included! This will be ignored from the merge.")
|
|
continue
|
|
out_ids.append(reddit_id)
|
|
del entry['_reddit_id']
|
|
|
|
if '_author' in entry:
|
|
author = entry['_author']
|
|
if author not in authors:
|
|
authors.append(author)
|
|
del entry['_author']
|
|
|
|
if entry['id'] in out_ids:
|
|
print(f"{filename}: Submission from {entry['id']} has been included! This will be ignored from the merge.")
|
|
continue
|
|
|
|
if entry['id'] < 1:
|
|
last_id += 1
|
|
print(f"{filename}: Entry is new, assigned ID {last_id}")
|
|
entry['id'] = str(last_id)
|
|
else:
|
|
out_ids.append(entry['id'])
|
|
|
|
|
|
if entry['id'] in atlas_ids:
|
|
index = atlas_ids[entry['id']]
|
|
print(f"{filename}: Edited {atlas_data[index]['id']}.")
|
|
atlas_data[index] = entry
|
|
else:
|
|
print(f"{filename}: Added {entry['id']}.")
|
|
atlas_data.append(entry)
|
|
|
|
os.remove(f)
|
|
|
|
print('Writing...')
|
|
with open('../web/atlas.json', 'w', encoding='utf-8') as atlas_file:
|
|
per_line_entries(atlas_data, atlas_file)
|
|
|
|
with open('../data/read-ids.txt', 'w', encoding='utf-8') as ids_file:
|
|
ids_file.write("\n".join(out_ids) + "\n")
|
|
|
|
with open('../web/all-authors.txt', 'w', encoding='utf-8') as authors_file:
|
|
authors_file.write("\n".join(authors) + "\n")
|
|
|
|
print('All done.') |