mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-08-09 10:39:11 +02:00
Skip invalid ownerless JSON rows (#1540)
This commit is contained in:
parent
7cf39a927b
commit
6f9582e3af
2 changed files with 31 additions and 5 deletions
|
|
@ -13,6 +13,18 @@ import json
|
|||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
|
||||
def claim_json_entries(entries, owner):
|
||||
count = 0
|
||||
for entry in entries:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
if not entry.get("owner"):
|
||||
entry["owner"] = owner
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python scripts/claim_ownerless.py <username>")
|
||||
|
|
@ -31,11 +43,7 @@ def main():
|
|||
continue
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
entries = json.load(f)
|
||||
count = 0
|
||||
for e in entries:
|
||||
if not e.get("owner"):
|
||||
e["owner"] = owner
|
||||
count += 1
|
||||
count = claim_json_entries(entries, owner)
|
||||
if count:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(entries, f, ensure_ascii=False, indent=2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue