forked from edward/owl-map
Add some types and other fixes.
This commit is contained in:
parent
f34226c8d7
commit
40e9499eb6
17
update.py
17
update.py
|
@ -5,6 +5,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import typing
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from matcher import database, model, utils, wikidata, wikidata_api
|
from matcher import database, model, utils, wikidata, wikidata_api
|
||||||
|
@ -12,13 +13,13 @@ from matcher import database, model, utils, wikidata, wikidata_api
|
||||||
DB_URL = "postgresql:///matcher"
|
DB_URL = "postgresql:///matcher"
|
||||||
database.init_db(DB_URL)
|
database.init_db(DB_URL)
|
||||||
|
|
||||||
previous_max_lastrevid = 1388804050 # Q106152661
|
previous_max_lastrevid = 1888214110 # Q118129609
|
||||||
|
|
||||||
entity_keys = {"labels", "sitelinks", "aliases", "claims", "descriptions", "lastrevid"}
|
entity_keys = {"labels", "sitelinks", "aliases", "claims", "descriptions", "lastrevid"}
|
||||||
|
|
||||||
|
|
||||||
def read_changes():
|
def read_changes() -> None:
|
||||||
qids = set()
|
qids: set[str] = set()
|
||||||
max_lastrevid = 0
|
max_lastrevid = 0
|
||||||
for f in sorted(os.listdir("changes"), key=lambda f: int(f.partition(".")[0])):
|
for f in sorted(os.listdir("changes"), key=lambda f: int(f.partition(".")[0])):
|
||||||
reply = json.load(open("changes/" + f))
|
reply = json.load(open("changes/" + f))
|
||||||
|
@ -43,7 +44,8 @@ def read_changes():
|
||||||
json.dump(entity, out)
|
json.dump(entity, out)
|
||||||
|
|
||||||
|
|
||||||
def get_changes():
|
def get_changes() -> None:
|
||||||
|
"""Get recent changes."""
|
||||||
start = "2021-03-24T11:56:11"
|
start = "2021-03-24T11:56:11"
|
||||||
rccontinue = None
|
rccontinue = None
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -157,7 +159,7 @@ def handle_new(change):
|
||||||
database.session.add(item)
|
database.session.add(item)
|
||||||
|
|
||||||
|
|
||||||
def coords_equal(a, b):
|
def coords_equal(a: dict[str, typing.Any], b: dict[str, typing.Any]) -> bool:
|
||||||
"""Deep equality comparison of nested dicts."""
|
"""Deep equality comparison of nested dicts."""
|
||||||
return json.dumps(a, sort_keys=True) == json.dumps(b, sort_keys=True)
|
return json.dumps(a, sort_keys=True) == json.dumps(b, sort_keys=True)
|
||||||
|
|
||||||
|
@ -198,13 +200,14 @@ def handle_edit(change):
|
||||||
setattr(item, key, entity[key])
|
setattr(item, key, entity[key])
|
||||||
|
|
||||||
|
|
||||||
def update_timestamp(timestamp):
|
def update_timestamp(timestamp: str) -> None:
|
||||||
|
"""Save timestamp to rc_timestamp."""
|
||||||
out = open("rc_timestamp", "w")
|
out = open("rc_timestamp", "w")
|
||||||
print(timestamp, file=out)
|
print(timestamp, file=out)
|
||||||
out.close()
|
out.close()
|
||||||
|
|
||||||
|
|
||||||
def update_database():
|
def update_database() -> None:
|
||||||
with open("rc_timestamp") as f:
|
with open("rc_timestamp") as f:
|
||||||
start = f.read().strip()
|
start = f.read().strip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue