mirror of
https://github.com/task-17-lct/backend.git
synced 2024-11-23 23:03:44 +03:00
loaded osm objects
This commit is contained in:
parent
ed8721b94d
commit
44c20e4b7e
|
@ -17,24 +17,34 @@
|
||||||
"parser_source": "openstreetmap.org",
|
"parser_source": "openstreetmap.org",
|
||||||
"lat": el["lat"],
|
"lat": el["lat"],
|
||||||
"lon": el["lon"],
|
"lon": el["lon"],
|
||||||
"extra_kwargs": info,
|
|
||||||
}
|
}
|
||||||
if "addr:full" in info:
|
if "addr:full" in info:
|
||||||
res["address"] = info["addr:full"]
|
res["address"] = info["addr:full"]
|
||||||
else:
|
else:
|
||||||
res = []
|
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
|
||||||
|
|
||||||
if "description" in info:
|
if "description" in info:
|
||||||
res["description"] = info["description"]
|
res["description"] = info["description"]
|
||||||
|
|
||||||
if "email" in info:
|
res["extra_kwargs"] = info
|
||||||
res["email"] = info["email"]
|
|
||||||
|
|
||||||
ress.append(res)
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
def get_artwork():
|
def get_artwork():
|
||||||
return ress
|
return ress
|
||||||
|
|
||||||
|
|
||||||
print([x for x in ress if "address" in x][:10])
|
|
||||||
|
|
50
parsers/osm/attraction.py
Normal file
50
parsers/osm/attraction.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/attraction.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": "attraction",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_attraction():
|
||||||
|
return ress
|
56
parsers/osm/bar.py
Normal file
56
parsers/osm/bar.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/bars.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": "bar",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
if "opening_hours" in info:
|
||||||
|
res["working_time"] = {"opening_hours": info["opening_hours"]}
|
||||||
|
|
||||||
|
if "phone" in info:
|
||||||
|
res["phones"] = [info["phone"]]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_bar():
|
||||||
|
return ress
|
56
parsers/osm/cafes.py
Normal file
56
parsers/osm/cafes.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/cafes.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": "cafe",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
if "opening_hours" in info:
|
||||||
|
res["working_time"] = {"opening_hours": info["opening_hours"]}
|
||||||
|
|
||||||
|
if "phone" in info:
|
||||||
|
res["phones"] = [info["phone"]]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_cafe():
|
||||||
|
return ress
|
50
parsers/osm/gallery.py
Normal file
50
parsers/osm/gallery.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/gallery.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": "gallery",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_gallery():
|
||||||
|
return ress
|
64
parsers/osm/other.py
Normal file
64
parsers/osm/other.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/other.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
nodes_loc = {}
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "lat" in el and "lon" in el:
|
||||||
|
nodes_loc[el["id"]] = [el["lat"], el["lon"]]
|
||||||
|
|
||||||
|
|
||||||
|
ress = []
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "tags" in el and "name" in el["tags"] and "lat" in el and "lon" in el:
|
||||||
|
nodes = []
|
||||||
|
|
||||||
|
if "nodes" in el:
|
||||||
|
nodes = [nodes_loc[x] for x in el["nodes"]]
|
||||||
|
|
||||||
|
info = el["tags"]
|
||||||
|
if "tourism" in info:
|
||||||
|
del info["tourism"]
|
||||||
|
res = {
|
||||||
|
"title": info["name:ru"] if "name:ru" in info else info["name"],
|
||||||
|
"type": "other",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
if nodes:
|
||||||
|
res["extra_kwargs"]["nodes"] = nodes
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_other():
|
||||||
|
return ress
|
56
parsers/osm/restaurant.py
Normal file
56
parsers/osm/restaurant.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/restaurants.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": "restaurant",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
if "opening_hours" in info:
|
||||||
|
res["working_time"] = {"opening_hours": info["opening_hours"]}
|
||||||
|
|
||||||
|
if "phone" in info:
|
||||||
|
res["phones"] = [info["phone"]]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_res():
|
||||||
|
return ress
|
64
parsers/osm/shop.py
Normal file
64
parsers/osm/shop.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/shops.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
nodes_loc = {}
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "lat" in el and "lon" in el:
|
||||||
|
nodes_loc[el["id"]] = [el["lat"], el["lon"]]
|
||||||
|
|
||||||
|
|
||||||
|
ress = []
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "tags" in el and "name" in el["tags"] and "lat" in el and "lon" in el:
|
||||||
|
nodes = []
|
||||||
|
|
||||||
|
if "nodes" in el:
|
||||||
|
nodes = [nodes_loc[x] for x in el["nodes"]]
|
||||||
|
|
||||||
|
info = el["tags"]
|
||||||
|
if "tourism" in info:
|
||||||
|
del info["tourism"]
|
||||||
|
res = {
|
||||||
|
"title": info["name:ru"] if "name:ru" in info else info["name"],
|
||||||
|
"type": "shop",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
if nodes:
|
||||||
|
res["extra_kwargs"]["nodes"] = nodes
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_shops():
|
||||||
|
return ress
|
64
parsers/osm/theme_park.py
Normal file
64
parsers/osm/theme_park.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/theme_park.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
nodes_loc = {}
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "lat" in el and "lon" in el:
|
||||||
|
nodes_loc[el["id"]] = [el["lat"], el["lon"]]
|
||||||
|
|
||||||
|
|
||||||
|
ress = []
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "tags" in el and "name" in el["tags"] and "lat" in el and "lon" in el:
|
||||||
|
nodes = []
|
||||||
|
|
||||||
|
if "nodes" in el:
|
||||||
|
nodes = [nodes_loc[x] for x in el["nodes"]]
|
||||||
|
|
||||||
|
info = el["tags"]
|
||||||
|
if "tourism" in info:
|
||||||
|
del info["tourism"]
|
||||||
|
res = {
|
||||||
|
"title": info["name:ru"] if "name:ru" in info else info["name"],
|
||||||
|
"type": "theme_park",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
if nodes:
|
||||||
|
res["extra_kwargs"]["nodes"] = nodes
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_theme_park():
|
||||||
|
return ress
|
64
parsers/osm/viewpoint.py
Normal file
64
parsers/osm/viewpoint.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/viewpoint.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
nodes_loc = {}
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "lat" in el and "lon" in el:
|
||||||
|
nodes_loc[el["id"]] = [el["lat"], el["lon"]]
|
||||||
|
|
||||||
|
|
||||||
|
ress = []
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "tags" in el and "name" in el["tags"] and "lat" in el and "lon" in el:
|
||||||
|
nodes = []
|
||||||
|
|
||||||
|
if "nodes" in el:
|
||||||
|
nodes = [nodes_loc[x] for x in el["nodes"]]
|
||||||
|
|
||||||
|
info = el["tags"]
|
||||||
|
if "tourism" in info:
|
||||||
|
del info["tourism"]
|
||||||
|
res = {
|
||||||
|
"title": info["name:ru"] if "name:ru" in info else info["name"],
|
||||||
|
"type": "viewpoint",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
if nodes:
|
||||||
|
res["extra_kwargs"]["nodes"] = nodes
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_viewpoint():
|
||||||
|
return ress
|
64
parsers/osm/zoo.py
Normal file
64
parsers/osm/zoo.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("data/osm/zoo.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
nodes_loc = {}
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "lat" in el and "lon" in el:
|
||||||
|
nodes_loc[el["id"]] = [el["lat"], el["lon"]]
|
||||||
|
|
||||||
|
|
||||||
|
ress = []
|
||||||
|
|
||||||
|
for el in data["elements"]:
|
||||||
|
if "tags" in el and "name" in el["tags"] and "lat" in el and "lon" in el:
|
||||||
|
nodes = []
|
||||||
|
|
||||||
|
if "nodes" in el:
|
||||||
|
nodes = [nodes_loc[x] for x in el["nodes"]]
|
||||||
|
|
||||||
|
info = el["tags"]
|
||||||
|
if "tourism" in info:
|
||||||
|
del info["tourism"]
|
||||||
|
res = {
|
||||||
|
"title": info["name:ru"] if "name:ru" in info else info["name"],
|
||||||
|
"type": "zoo",
|
||||||
|
"parser_source": "openstreetmap.org",
|
||||||
|
"lat": el["lat"],
|
||||||
|
"lon": el["lon"],
|
||||||
|
}
|
||||||
|
if "addr:full" in info:
|
||||||
|
res["address"] = info["addr:full"]
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
||||||
|
if "description" in info:
|
||||||
|
res["description"] = info["description"]
|
||||||
|
|
||||||
|
res["extra_kwargs"] = info
|
||||||
|
|
||||||
|
if nodes:
|
||||||
|
res["extra_kwargs"]["nodes"] = nodes
|
||||||
|
|
||||||
|
ress.append(res)
|
||||||
|
|
||||||
|
|
||||||
|
def get_zoo():
|
||||||
|
return ress
|
18
passfinder/events/migrations/0023_restaurant_extra_kwargs.py
Normal file
18
passfinder/events/migrations/0023_restaurant_extra_kwargs.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-05-26 13:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("events", "0022_restaurant_type_alter_event_type_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="extra_kwargs",
|
||||||
|
field=models.JSONField(null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -231,6 +231,8 @@ class RestaurantType(models.TextChoices):
|
||||||
working_time = models.JSONField(null=True)
|
working_time = models.JSONField(null=True)
|
||||||
phones = ArrayField(models.CharField(max_length=18), null=True)
|
phones = ArrayField(models.CharField(max_length=18), null=True)
|
||||||
|
|
||||||
|
extra_kwargs = models.JSONField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class UserRoute(models.Model):
|
class UserRoute(models.Model):
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user