mirror of
https://github.com/task-17-lct/backend.git
synced 2024-11-24 02:53:43 +03:00
Merge branch 'master' into recsys-init
This commit is contained in:
commit
aa40ce39cb
63
parsers/hotel.py
Normal file
63
parsers/hotel.py
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import json
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from django.contrib.gis.geos import Point
|
||||||
|
|
||||||
|
from passfinder.events.models import City, Region
|
||||||
|
|
||||||
|
with open("data/hotels.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for r in data:
|
||||||
|
d = {}
|
||||||
|
al = True
|
||||||
|
info = r["dictionary_data"]
|
||||||
|
d["oid"] = r["_id"]["$oid"]
|
||||||
|
d["title"] = info["title"]
|
||||||
|
d["address"] = info["address"]
|
||||||
|
if "stars" in info and info["stars"]:
|
||||||
|
d["stars"] = int(info["stars"])
|
||||||
|
|
||||||
|
if "city" in info:
|
||||||
|
try:
|
||||||
|
d["city"] = City.objects.get(oid=info["city"])
|
||||||
|
except City.DoesNotExist:
|
||||||
|
...
|
||||||
|
if "region" in info:
|
||||||
|
try:
|
||||||
|
d["region"] = Region.objects.get(oid=info["region"])
|
||||||
|
except Region.DoesNotExist:
|
||||||
|
...
|
||||||
|
if "geo_data" in info and info["geo_data"]["coordinates"]:
|
||||||
|
d["location"] = Point(
|
||||||
|
info["geo_data"]["coordinates"][0], info["geo_data"]["coordinates"][1]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
al = False
|
||||||
|
if "rooms" in info:
|
||||||
|
d["rooms"] = info["rooms"]
|
||||||
|
|
||||||
|
phones = []
|
||||||
|
if "phones" in info:
|
||||||
|
for phone in info["phones"]:
|
||||||
|
phones.append(
|
||||||
|
{"hotel": d["oid"], "name": phone["name"], "number": phone["number"]}
|
||||||
|
)
|
||||||
|
if phones:
|
||||||
|
d["phones"] = phones
|
||||||
|
|
||||||
|
media = []
|
||||||
|
if "images" in info:
|
||||||
|
for m in info["images"]:
|
||||||
|
media.append({"file": m["source"]["id"], "type": "image"})
|
||||||
|
if media:
|
||||||
|
d["media"] = media
|
||||||
|
|
||||||
|
if al:
|
||||||
|
result.append(d)
|
||||||
|
|
||||||
|
|
||||||
|
def get_hotel():
|
||||||
|
return result
|
67
parsers/restaurant.py
Normal file
67
parsers/restaurant.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import json
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from django.contrib.gis.geos import Point
|
||||||
|
|
||||||
|
from passfinder.events.models import City, Region
|
||||||
|
|
||||||
|
with open("data/restaurants.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for r in data:
|
||||||
|
d = {}
|
||||||
|
al = True
|
||||||
|
info = r["dictionary_data"]
|
||||||
|
d["oid"] = r["_id"]["$oid"]
|
||||||
|
d["title"] = info["title"]
|
||||||
|
if "description" in info:
|
||||||
|
d["description"] = info["description"]
|
||||||
|
else:
|
||||||
|
d["description"] = ""
|
||||||
|
d["address"] = info["address"]
|
||||||
|
if "bill" in info:
|
||||||
|
d["bill"] = int(info["bill"])
|
||||||
|
if "parser_source" in info:
|
||||||
|
d["parser_source"] = info["parser_source"]
|
||||||
|
if "avg_time_visit" in info:
|
||||||
|
d["avg_time_visit"] = int(info["avg_time_visit"])
|
||||||
|
if "can_reserve" in info:
|
||||||
|
d["can_reserve"] = bool(info["can_reserve"])
|
||||||
|
if "working_time" in info:
|
||||||
|
d["working_time"] = info["working_time"]
|
||||||
|
if "phones" in info and info["phones"]:
|
||||||
|
d["phones"] = info["phones"]
|
||||||
|
|
||||||
|
if "city" in info:
|
||||||
|
try:
|
||||||
|
d["city"] = City.objects.get(oid=info["city"])
|
||||||
|
except City.DoesNotExist:
|
||||||
|
...
|
||||||
|
if "region" in info:
|
||||||
|
try:
|
||||||
|
d["region"] = Region.objects.get(oid=info["region"])
|
||||||
|
except Region.DoesNotExist:
|
||||||
|
...
|
||||||
|
|
||||||
|
if "geo_data" in info and info["geo_data"]["coordinates"]:
|
||||||
|
d["location"] = Point(
|
||||||
|
info["geo_data"]["coordinates"][0], info["geo_data"]["coordinates"][1]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
al = False
|
||||||
|
|
||||||
|
media = []
|
||||||
|
if "images" in info:
|
||||||
|
for m in info["images"]:
|
||||||
|
media.append({"file": m["source"]["id"], "type": "image"})
|
||||||
|
if media and 1 == 2:
|
||||||
|
d["media"] = media
|
||||||
|
|
||||||
|
if al:
|
||||||
|
result.append(d)
|
||||||
|
|
||||||
|
|
||||||
|
def get_restaurant():
|
||||||
|
return result
|
19
passfinder/events/migrations/0012_restaurant_address.py
Normal file
19
passfinder/events/migrations/0012_restaurant_address.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-05-21 06:58
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("events", "0011_remove_event_purchase_method_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="address",
|
||||||
|
field=models.CharField(default="", max_length=250),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-05-21 07:05
|
||||||
|
|
||||||
|
import django.contrib.postgres.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("events", "0012_restaurant_address"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="phone",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="phones",
|
||||||
|
field=django.contrib.postgres.fields.ArrayField(
|
||||||
|
base_field=models.CharField(max_length=18), null=True, size=None
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="avg_time_visit",
|
||||||
|
field=models.IntegerField(null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="bill",
|
||||||
|
field=models.IntegerField(null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="restaurant",
|
||||||
|
name="can_reserve",
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -155,8 +155,9 @@ class ExcursionRoute(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Restaurant(BasePoint):
|
class Restaurant(BasePoint):
|
||||||
bill = models.IntegerField()
|
address = models.CharField(max_length=250)
|
||||||
avg_time_visit = models.IntegerField()
|
bill = models.IntegerField(null=True)
|
||||||
can_reserve = models.BooleanField()
|
can_reserve = models.BooleanField(default=True)
|
||||||
|
avg_time_visit = models.IntegerField(null=True)
|
||||||
working_time = models.JSONField(null=True)
|
working_time = models.JSONField(null=True)
|
||||||
phone = models.CharField(max_length=18)
|
phones = ArrayField(models.CharField(max_length=18), null=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user