From 1771f19f56dcc24643ff64c75d270dca10684f7e Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 13 Nov 2021 16:39:03 +0000 Subject: [PATCH] Alert admin about unsupported time precision --- matcher/model.py | 19 +++++++++++++++++-- matcher/utils.py | 2 -- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/matcher/model.py b/matcher/model.py index ac38705..e72c113 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -11,7 +11,7 @@ from geoalchemy2 import Geometry from collections import defaultdict from flask_login import UserMixin from .database import session, now_utc -from . import wikidata, utils +from . import wikidata, utils, mail import json import re @@ -197,8 +197,23 @@ class Item(Base): def is_tram_stop(self): return 'Q2175765' in self.get_isa_qids() + def alert_admin_about_bad_time(self, v): + body = ("Wikidata item has an unsupported time precision\n\n" + + self.wd_url + "\n\n" + "Value:\n\n" + json.dumps(v, indent=2)) + mail.send_mail(f"OWL Map: bad time value in {self.qid}", body) + def closed(self): - return [utils.format_wikibase_time(v) for v in self.get_claim("P3999") if v] + ret = [] + for v in self.get_claim("P3999"): + if not v: + continue + t = utils.format_wikibase_time(v) + if t: + ret.append(t) + else: + self.alert_admin_about_bad_time(v) + + return ret # class Claim(Base): # __tablename__ = "claim" diff --git a/matcher/utils.py b/matcher/utils.py index fcdb5d8..81335a0 100644 --- a/matcher/utils.py +++ b/matcher/utils.py @@ -176,8 +176,6 @@ def format_wikibase_time(v): p = v["precision"] t = v["time"] - assert p in (7, 9, 10, 11) - # TODO: handle dates with century precision (7) # example: https://www.wikidata.org/wiki/Q108266998