diff --git a/parsers/osm/artwork.py b/parsers/osm/artwork.py index e40372e..5013de7 100644 --- a/parsers/osm/artwork.py +++ b/parsers/osm/artwork.py @@ -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]) diff --git a/parsers/osm/attraction.py b/parsers/osm/attraction.py new file mode 100644 index 0000000..6601b06 --- /dev/null +++ b/parsers/osm/attraction.py @@ -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 diff --git a/parsers/osm/bar.py b/parsers/osm/bar.py new file mode 100644 index 0000000..f6ecd0c --- /dev/null +++ b/parsers/osm/bar.py @@ -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 diff --git a/parsers/osm/cafes.py b/parsers/osm/cafes.py new file mode 100644 index 0000000..ceb3b89 --- /dev/null +++ b/parsers/osm/cafes.py @@ -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 diff --git a/parsers/osm/gallery.py b/parsers/osm/gallery.py new file mode 100644 index 0000000..05e631a --- /dev/null +++ b/parsers/osm/gallery.py @@ -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 diff --git a/parsers/osm/other.py b/parsers/osm/other.py new file mode 100644 index 0000000..3ef1574 --- /dev/null +++ b/parsers/osm/other.py @@ -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 diff --git a/parsers/osm/restaurant.py b/parsers/osm/restaurant.py new file mode 100644 index 0000000..659388e --- /dev/null +++ b/parsers/osm/restaurant.py @@ -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 diff --git a/parsers/osm/shop.py b/parsers/osm/shop.py new file mode 100644 index 0000000..6a48816 --- /dev/null +++ b/parsers/osm/shop.py @@ -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 diff --git a/parsers/osm/theme_park.py b/parsers/osm/theme_park.py new file mode 100644 index 0000000..e794f9a --- /dev/null +++ b/parsers/osm/theme_park.py @@ -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 diff --git a/parsers/osm/viewpoint.py b/parsers/osm/viewpoint.py new file mode 100644 index 0000000..8973849 --- /dev/null +++ b/parsers/osm/viewpoint.py @@ -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 diff --git a/parsers/osm/zoo.py b/parsers/osm/zoo.py new file mode 100644 index 0000000..a22fab9 --- /dev/null +++ b/parsers/osm/zoo.py @@ -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 diff --git a/passfinder/events/migrations/0023_restaurant_extra_kwargs.py b/passfinder/events/migrations/0023_restaurant_extra_kwargs.py new file mode 100644 index 0000000..561f8b7 --- /dev/null +++ b/passfinder/events/migrations/0023_restaurant_extra_kwargs.py @@ -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), + ), + ] diff --git a/passfinder/events/models.py b/passfinder/events/models.py index 9866e5b..e1e784d 100644 --- a/passfinder/events/models.py +++ b/passfinder/events/models.py @@ -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(