Show date close date (P3999) in item detail

This commit is contained in:
Edward Betts 2021-07-02 11:08:53 +02:00
parent 72c32f38ce
commit 0aa2bfc4b7
3 changed files with 25 additions and 2 deletions

View file

@ -321,6 +321,11 @@
<br>{{wd_item.street_address[0]}} <br>{{wd_item.street_address[0]}}
</span> </span>
<span v-if="wd_item.closed.length">
<br><strong>closed</strong>
<br>{{wd_item.closed.join('; ')}}
</span>
</div> </div>
<div class="col"> <div class="col">

View file

@ -145,18 +145,21 @@ class Item(Base):
return dict(d) or None return dict(d) or None
def get_isa_qids(self): def get_isa_qids(self):
return {v["id"] for v in self.get_claim("P31") if v} return [v["id"] for v in self.get_claim("P31") if v]
def is_street(self): def is_street(self):
street_items = { street_items = {
'Q79007', # street 'Q79007', # street
'Q21000333', # shopping street 'Q21000333', # shopping street
} }
return bool(street_items & self.get_isa_qids()) return bool(street_items & set(self.get_isa_qids()))
def is_tram_stop(self): def is_tram_stop(self):
return 'Q2175765' in self.get_isa_qids() return 'Q2175765' in self.get_isa_qids()
def closed(self):
return [utils.format_wikibase_time(v) for v in self.get_claim("P3999") if v]
# class Claim(Base): # class Claim(Base):
# __tablename__ = "claim" # __tablename__ = "claim"
# item_id = Column(Integer, primary_key=True) # item_id = Column(Integer, primary_key=True)

View file

@ -6,6 +6,7 @@ import math
import user_agents import user_agents
import re import re
import pattern.en import pattern.en
from datetime import date
metres_per_mile = 1609.344 metres_per_mile = 1609.344
feet_per_metre = 3.28084 feet_per_metre = 3.28084
@ -168,3 +169,17 @@ def pluralize_label(label):
return "mines" return "mines"
return pattern.en.pluralize(text) return pattern.en.pluralize(text)
def format_wikibase_time(v):
p = v["precision"]
t = v["time"]
assert p in (9, 10, 11)
if p == 11:
return date.fromisoformat(t[1:11]).strftime("%d %B %Y")
if p == 10:
return date.fromisoformat(t[1:8] + "-01").strftime("%B %Y")
if p == 9:
return t[1:5]