backend/parsers/osm/artwork.py

51 lines
1.4 KiB
Python
Raw Normal View History

2023-05-26 11:55:02 +03:00
import json
with open("data/osm/artwork.json") as f:
data = json.load(f)
ress = []
for el in data["elements"]:
if "tags" in el and "name" in el["tags"] and "lat" in el and "lon" in el:
info = el["tags"]
if "tourism" in info:
del info["tourism"]
res = {
"title": info["name:ru"] if "name:ru" in info else info["name"],
"type": "artwork",
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
}
if "addr:full" in info:
res["address"] = info["addr:full"]
else:
2023-05-26 16:26:01 +03:00
addr_res = ""
names = [x.split(":")[1] for x in info.keys() if "addr:" in x]
for nnn in ["postcode", "city", "street", "housenumber"]:
if nnn in names:
val = info["addr:" + nnn]
if addr_res:
if nnn in ["city", "street"]:
addr_res += f", {val}"
else:
addr_res += f" {val}"
else:
addr_res = val
if addr_res:
res["address"] = addr_res
2023-05-26 11:55:02 +03:00
if "description" in info:
res["description"] = info["description"]
2023-05-26 16:26:01 +03:00
res["extra_kwargs"] = info
2023-05-26 11:55:02 +03:00
ress.append(res)
def get_artwork():
return ress