loaded hotels

This commit is contained in:
Alexander Karpov 2023-05-26 01:45:14 +03:00
parent 8c755fe700
commit a94771d421
9 changed files with 228 additions and 4585 deletions

File diff suppressed because it is too large Load Diff

39
parsers/osm/apartment.py Normal file
View File

@ -0,0 +1,39 @@
import json
with open("data/osm/apartment.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": "apartment",
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
"extra_kwargs": info,
}
if "rooms" in info:
res["rooms"] = {"amount": info["rooms"]}
if "description" in info:
res["description"] = info["description"]
if "email" in info:
res["email"] = info["email"]
if "stars" in info:
res["stars"] = int(float(info["stars"]))
else:
res["stars"] = 0
ress.append(res)
def get_hotels():
return ress

39
parsers/osm/chalet.py Normal file
View File

@ -0,0 +1,39 @@
import json
with open("data/osm/chalet.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": "chalet",
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
"extra_kwargs": info,
}
if "rooms" in info:
res["rooms"] = {"amount": info["rooms"]}
if "description" in info:
res["description"] = info["description"]
if "email" in info:
res["email"] = info["email"]
if "stars" in info:
res["stars"] = int(float(info["stars"]))
else:
res["stars"] = 0
ress.append(res)
def get_hotels():
return ress

View File

@ -0,0 +1,39 @@
import json
with open("data/osm/hostel_2.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": "guest_house",
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
"extra_kwargs": info,
}
if "rooms" in info:
res["rooms"] = {"amount": info["rooms"]}
if "description" in info:
res["description"] = info["description"]
if "email" in info:
res["email"] = info["email"]
if "stars" in info:
res["stars"] = int(float(info["stars"]))
else:
res["stars"] = 0
ress.append(res)
def get_hostels():
return ress

39
parsers/osm/hostels.py Normal file
View File

@ -0,0 +1,39 @@
import json
with open("data/osm/hostel.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": "hostel",
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
"extra_kwargs": info,
}
if "rooms" in info:
res["rooms"] = {"amount": info["rooms"]}
if "description" in info:
res["description"] = info["description"]
if "email" in info:
res["email"] = info["email"]
if "stars" in info:
res["stars"] = int(float(info["stars"]))
else:
res["stars"] = 0
ress.append(res)
def get_hostels():
return ress

39
parsers/osm/motel.py Normal file
View File

@ -0,0 +1,39 @@
import json
with open("data/osm/motel.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": "motel",
"parser_source": "openstreetmap.org",
"lat": el["lat"],
"lon": el["lon"],
"extra_kwargs": info,
}
if "rooms" in info:
res["rooms"] = {"amount": info["rooms"]}
if "description" in info:
res["description"] = info["description"]
if "email" in info:
res["email"] = info["email"]
if "stars" in info:
res["stars"] = int(float(info["stars"]))
else:
res["stars"] = 0
ress.append(res)
def get_hotels():
return ress

View File

@ -36,11 +36,9 @@ class Meta:
class EventSerializer(serializers.ModelSerializer):
city_name = serializers.CharField(source="city.title")
class Meta:
model = Event
fields = ("type", "title", "description", "city", "city_name", "oid")
fields = ("type", "title", "description", "city", "oid")
class PointSerializer(serializers.ModelSerializer):

View File

@ -0,0 +1,30 @@
# Generated by Django 4.2.1 on 2023-05-25 22:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("events", "0020_hotel_extra_kwargs_hotel_type_alter_hotel_address_and_more"),
]
operations = [
migrations.AlterField(
model_name="hotel",
name="type",
field=models.CharField(
choices=[
("hotel", "отель"),
("hostel", "хостел"),
("guest_house", "гостевой дом"),
("motel", "мотель"),
("apartment", "квартира"),
("chalet", "домик"),
],
db_index=True,
default="hotel",
max_length=11,
),
),
]

View File

@ -182,6 +182,8 @@ class HotelType(models.TextChoices):
hostel = "hostel", "хостел"
guest_house = "guest_house", "гостевой дом"
motel = "motel", "мотель"
apartment = "apartment", "квартира"
chalet = "chalet", "домик"
type = models.CharField(
db_index=True,