From b9b9728fc69e4fe3723c17b9f46351891ac59618 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 14 May 2023 14:00:45 +0000 Subject: [PATCH] Add more types. --- update.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/update.py b/update.py index 4ebe3e0..3ebee24 100755 --- a/update.py +++ b/update.py @@ -14,7 +14,17 @@ database.init_db(DB_URL) entity_keys = {"labels", "sitelinks", "aliases", "claims", "descriptions", "lastrevid"} -def handle_new(change): +class Change(typing.TypedDict): + """Dict representing an edit in recent changes.""" + + title: str + timestamp: str + redirect: dict[str, typing.Any] | None + revid: int + + +def handle_new(change: Change) -> None: + """Handle a new Wikidata item from the recent changes feed.""" qid = change["title"] ts = change["timestamp"] if change["redirect"]: @@ -57,7 +67,8 @@ def coords_equal(a: dict[str, typing.Any], b: dict[str, typing.Any]) -> bool: return json.dumps(a, sort_keys=True) == json.dumps(b, sort_keys=True) -def handle_edit(change): +def handle_edit(change: Change) -> None: + """Process an edit from recent changes.""" qid = change["title"] item = model.Item.query.get(qid[1:]) if not item: @@ -101,6 +112,7 @@ def update_timestamp(timestamp: str) -> None: def update_database() -> None: + """Check recent changes and apply updates to local mirror of Wikidata.""" with open("rc_timestamp") as f: start = f.read().strip()