From 22cfe648963920ed0b427826853d0b2629f129b7 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 3 Jul 2021 13:39:37 +0200 Subject: [PATCH] Include more detail in OSM tags API call --- matcher/api.py | 52 ++++++++++++++++++++++++++------------------------ web_view.py | 4 +++- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/matcher/api.py b/matcher/api.py index f381195..d9d9847 100644 --- a/matcher/api.py +++ b/matcher/api.py @@ -495,32 +495,34 @@ def get_item_street_addresses(item): def check_is_street_number_first(bounds): g.street_number_first = is_street_number_first(*get_bbox_centroid(bounds)) +def item_detail(item): + locations = [list(i.get_lat_lon()) for i in item.locations] + if not hasattr(g, 'street_number_first'): + g.street_number_first = is_street_number_first(*locations[0]) + + image_filenames = item.get_claim("P18") + + street_address = get_item_street_addresses(item) + + d = { + "qid": item.qid, + "label": item.label(), + "description": item.description(), + "markers": locations, + "image_list": image_filenames, + "street_address": street_address, + "isa_list": item.get_isa_qids(), + "closed": item.closed(), + } + + if aliases := item.get_aliases(): + d["aliases"] = aliases + + return d + + def get_markers(all_items): - items = [] - for item in all_items: - if not item: - continue - locations = [list(i.get_lat_lon()) for i in item.locations] - image_filenames = item.get_claim("P18") - - street_address = get_item_street_addresses(item) - - d = { - "qid": item.qid, - "label": item.label(), - "description": item.description(), - "markers": locations, - "image_list": image_filenames, - "street_address": street_address, - "isa_list": [v["id"] for v in item.get_claim("P31") if v], - } - - if aliases := item.get_aliases(): - d["aliases"] = aliases - - items.append(d) - - return items + return [item_detail(item) for item in all_items if item] def wikidata_items(bounds): diff --git a/web_view.py b/web_view.py index 41cb586..ece44d8 100755 --- a/web_view.py +++ b/web_view.py @@ -284,12 +284,14 @@ def api_osm_objects(): def api_get_item_tags(item_id): t0 = time() item = model.Item.query.get(item_id) - osm_list = api.get_item_tags(item) + tags = api.get_item_tags(item) + osm_list = sorted(tags.keys()) t1 = time() - t0 return cors_jsonify(success=True, qid=item.qid, tag_or_key_list=osm_list, + tag_src=tags, duration=t1)