Revert "Revert "Removed unused contributors field from JSON""

This reverts commit 7f735f9abc.
This commit is contained in:
Cheng Hann Gan 2022-05-13 10:16:50 -04:00
parent 7f735f9abc
commit d90baab00a
5 changed files with 7931 additions and 7979 deletions

View file

@ -2,11 +2,8 @@
import re import re
import json import json
import math
import traceback import traceback
from calculate_center import polylabel
""" """
Examples: Examples:
1. - /r/place 1. - /r/place
@ -263,11 +260,6 @@ def remove_empty_and_similar(entry: dict):
entry["links"][key] = [x for x in entry["links"][key] if x and x.lower() in small] entry["links"][key] = [x for x in entry["links"][key] if x and x.lower() in small]
if len(entry["links"][key]) == 0: del entry["links"][key] if len(entry["links"][key]) == 0: del entry["links"][key]
if "contributors" in entry:
if len(entry["contributors"]) == 0:
del entry["contributors"]
return entry return entry

View file

@ -1,10 +1,5 @@
import praw
import json import json
import time from formatter import per_line_entries
import re
import os
import traceback
from formatter import format_all, per_line_entries
out_ids = [] out_ids = []
out_dupe_ids = [] out_dupe_ids = []
@ -40,11 +35,6 @@
if 'edit' in entry: if 'edit' in entry:
out_edited_added_ids.append(entry['edit']) out_edited_added_ids.append(entry['edit'])
del entry['edit'] del entry['edit']
if 'submitted_by' in atlas_json[index]:
atlas_json[index]['contributors'] = [ atlas_json[index]['submitted_by'] ]
elif not 'contributors' in atlas_json[index]:
atlas_json[index]['contributors'] = []
entry['contributors'] = atlas_json[index]['contributors'] + list(set(entry['contributors']) - set(atlas_json[index]['contributors']))
atlas_json[index] = entry atlas_json[index] = entry
else: else:
print(f"Added {entry['id']}.") print(f"Added {entry['id']}.")

View file

@ -4,7 +4,7 @@
Migrator script from old atlas format to remastered atlas format. Migrator script from old atlas format to remastered atlas format.
- center and path: single -> time-specific - center and path: single -> time-specific
- website and subreddit: single strings -> links object - website and subreddit: single strings -> links object
- submitted_by -> contributors - submitted_by removed
""" """
import re import re
@ -25,8 +25,7 @@ def migrate_atlas_format(entry: dict):
"description": "", "description": "",
"links": {}, "links": {},
"path": {}, "path": {},
"center": {}, "center": {}
"contributors": []
} }
center = entry['center'] center = entry['center']
@ -67,10 +66,6 @@ def migrate_atlas_format(entry: dict):
new_entry['links']['subreddit'] = list(map(lambda x: FS_REGEX.sub(r"\1", x), COMMATIZATION.split(entry['subreddit']))) new_entry['links']['subreddit'] = list(map(lambda x: FS_REGEX.sub(r"\1", x), COMMATIZATION.split(entry['subreddit'])))
del entry['subreddit'] del entry['subreddit']
if "submitted_by" in entry:
new_entry['contributors'].append(entry['submitted_by'])
del entry['submitted_by']
toreturn = { toreturn = {
**new_entry, **new_entry,
**entry **entry

View file

@ -63,17 +63,6 @@
for id in [x.strip() for x in edit_ids_file.readlines()]: for id in [x.strip() for x in edit_ids_file.readlines()]:
existing_ids.append(id) existing_ids.append(id)
# with open('../web/atlas.json', 'r') as atlas_file:
# atlas_raw: list = json.loads(atlas_file)
# atlas = {}
# atlas_ids = []
# for index in atlas_raw:
# entry = atlas_raw[index]
# id = entry['id']
# del entry['id']
# atlas[id] = entry
# atlas_ids.append(id)
def set_flair(submission, flair): def set_flair(submission, flair):
if has_write_access and submission.link_flair_text != flair: if has_write_access and submission.link_flair_text != flair:
flair_choices = submission.flair.choices() flair_choices = submission.flair.choices()
@ -120,26 +109,12 @@ def set_flair(submission, flair):
assert submission_json["id"] != 0, "Edit invalid because ID is tampered, it must not be 0!" assert submission_json["id"] != 0, "Edit invalid because ID is tampered, it must not be 0!"
submission_json_dummy = {"id": submission_json["id"], "edit": submission.id} submission_json_dummy = {"id": submission_json["id"], "edit": submission.id}
submission_json["contributors"] = []
try:
if not submission.author.name in submission_json:
submission_json["contributors"].append(submission.author.name)
except AttributeError:
pass
else: else:
assert submission_json["id"] == 0, "Edit invalid because ID is tampered, it must be 0!" assert submission_json["id"] == 0, "Edit invalid because ID is tampered, it must be 0!"
submission_json_dummy = {"id": submission.id} submission_json_dummy = {"id": submission.id}
submission_json["contributors"] = []
try:
if not submission.author.name in submission_json:
submission_json["contributors"].append(submission.author.name)
except AttributeError:
pass
for key in submission_json: for key in submission_json:
if not key in submission_json_dummy: if not key in submission_json_dummy:

File diff suppressed because one or more lines are too long