loaded osm objects

This commit is contained in:
Alexander Karpov 2023-05-26 16:26:01 +03:00
parent 95be8a34be
commit c548985ed0
13 changed files with 625 additions and 7 deletions

View File

@ -17,24 +17,34 @@
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
"extra_kwargs": info,
}
if "addr:full" in info:
res["address"] = info["addr:full"]
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:
res["description"] = info["description"]
if "email" in info:
res["email"] = info["email"]
res["extra_kwargs"] = info
ress.append(res)
def get_artwork():
return ress
print([x for x in ress if "address" in x][:10])

50
parsers/osm/attraction.py Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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

View 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),
),
]

View File

@ -231,6 +231,8 @@ class RestaurantType(models.TextChoices):
working_time = models.JSONField(null=True)
phones = ArrayField(models.CharField(max_length=18), null=True)
extra_kwargs = models.JSONField(null=True)
class UserRoute(models.Model):
user = models.ForeignKey(