Item street address from P669

This commit is contained in:
Edward Betts 2021-05-14 17:02:21 +02:00
parent a7e0a5fa8e
commit fe4564cc7c

View file

@ -142,18 +142,41 @@ def get_items_in_bbox(bbox):
return q return q
def get_item_street_addresses(item):
street_address = [addr["text"] for addr in item.get_claim("P6375")]
if street_address or "P669" not in item.claims:
return street_address
for claim in item.claims["P669"]:
qualifiers = claim.get("qualifiers")
if not qualifiers or 'P670' not in qualifiers:
continue
number = qualifiers["P670"][0]["datavalue"]["value"]
street = get_item(claim["mainsnak"]["datavalue"]["value"]["numeric-id"])
street_name = street.label()
for q in qualifiers["P670"]:
number = q["datavalue"]["value"]
street_address.append(f"{street_name} {number}")
return street_address
def get_markers(all_items): def get_markers(all_items):
items = [] items = []
for item in all_items: for item in all_items:
locations = [list(i.get_lat_lon()) for i in item.locations] locations = [list(i.get_lat_lon()) for i in item.locations]
image_filenames = item.get_claim("P18") image_filenames = item.get_claim("P18")
street_address = get_item_street_addresses(item)
item = { item = {
"qid": item.qid, "qid": item.qid,
"label": item.label(), "label": item.label(),
"description": item.description(), "description": item.description(),
"markers": locations, "markers": locations,
"image_list": image_filenames, "image_list": image_filenames,
"street_address": item.get_claim("P6375"), "street_address": street_address,
"isa_list": [v["id"] for v in item.get_claim("P31")], "isa_list": [v["id"] for v in item.get_claim("P31")],
} }
items.append(item) items.append(item)