mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-05-29 01:25:10 +02:00
Implement per-entry patches 4
Continue when patch errors instead of ending the whole process
This commit is contained in:
parent
da4efb6c60
commit
4cbee4fee6
|
@ -2,6 +2,7 @@
|
||||||
import os
|
import os
|
||||||
from aformatter import format_all_entries, per_line_entries
|
from aformatter import format_all_entries, per_line_entries
|
||||||
import scale_back
|
import scale_back
|
||||||
|
import traceback
|
||||||
|
|
||||||
from scale_back import ScaleConfig
|
from scale_back import ScaleConfig
|
||||||
|
|
||||||
|
@ -50,44 +51,48 @@
|
||||||
if not os.path.isfile(f) or not f.endswith('json'):
|
if not os.path.isfile(f) or not f.endswith('json'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open(f, 'r', encoding='utf-8') as entry_file:
|
try:
|
||||||
entry = json.loads(entry_file.read())
|
with open(f, 'r', encoding='utf-8') as entry_file:
|
||||||
|
entry = json.loads(entry_file.read())
|
||||||
|
|
||||||
if '_reddit_id' in entry:
|
if '_reddit_id' in entry:
|
||||||
reddit_id = entry['_reddit_id']
|
reddit_id = entry['_reddit_id']
|
||||||
if reddit_id in out_ids:
|
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.")
|
print(f"{filename}: Submission from {entry['id']} has been included! This will be ignored from the merge.")
|
||||||
continue
|
continue
|
||||||
out_ids.append(reddit_id)
|
|
||||||
del entry['_reddit_id']
|
|
||||||
|
|
||||||
if '_author' in entry:
|
if entry['id'] < 1:
|
||||||
author = entry['_author']
|
last_id += 1
|
||||||
if author not in authors:
|
print(f"{filename}: Entry is new, assigned ID {last_id}")
|
||||||
authors.append(author)
|
entry['id'] = str(last_id)
|
||||||
del entry['_author']
|
else:
|
||||||
|
out_ids.append(entry['id'])
|
||||||
|
|
||||||
if entry['id'] in out_ids:
|
if entry['id'] in atlas_ids:
|
||||||
print(f"{filename}: Submission from {entry['id']} has been included! This will be ignored from the merge.")
|
index = atlas_ids[entry['id']]
|
||||||
continue
|
print(f"{filename}: Edited {atlas_data[index]['id']}.")
|
||||||
|
atlas_data[index] = entry
|
||||||
|
else:
|
||||||
|
print(f"{filename}: Added {entry['id']}.")
|
||||||
|
atlas_data.append(entry)
|
||||||
|
|
||||||
if entry['id'] < 1:
|
os.remove(f)
|
||||||
last_id += 1
|
|
||||||
print(f"{filename}: Entry is new, assigned ID {last_id}")
|
|
||||||
entry['id'] = str(last_id)
|
|
||||||
else:
|
|
||||||
out_ids.append(entry['id'])
|
|
||||||
|
|
||||||
|
except:
|
||||||
if entry['id'] in atlas_ids:
|
print(f"{filename}: Something went wrong; patch couldn't be implemented. Skipping.")
|
||||||
index = atlas_ids[entry['id']]
|
traceback.print_exc()
|
||||||
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...')
|
print('Writing...')
|
||||||
with open('../web/atlas.json', 'w', encoding='utf-8') as atlas_file:
|
with open('../web/atlas.json', 'w', encoding='utf-8') as atlas_file:
|
||||||
|
|
Loading…
Reference in a new issue