Merge branch 'master' into recsys-init

This commit is contained in:
Ilia vasilenko 2023-05-21 13:38:56 +03:00 committed by GitHub
commit aa40ce39cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 196 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

63
parsers/hotel.py Normal file
View 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
View 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

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

View File

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

View File

@ -155,8 +155,9 @@ class ExcursionRoute(models.Model):
class Restaurant(BasePoint):
bill = models.IntegerField()
avg_time_visit = models.IntegerField()
can_reserve = models.BooleanField()
address = models.CharField(max_length=250)
bill = models.IntegerField(null=True)
can_reserve = models.BooleanField(default=True)
avg_time_visit = models.IntegerField(null=True)
working_time = models.JSONField(null=True)
phone = models.CharField(max_length=18)
phones = ArrayField(models.CharField(max_length=18), null=True)

View File

@ -131,4 +131,4 @@ watchfiles==0.18.1 ; python_version >= "3.9" and python_version < "4.0"
wcwidth==0.2.6 ; python_version >= "3.9" and python_version < "4.0"
werkzeug[watchdog]==2.3.4 ; python_version >= "3.9" and python_version < "4.0"
whitenoise==6.4.0 ; python_version >= "3.9" and python_version < "4.0"
wrapt==1.15.0 ; python_version >= "3.9" and python_version < "4.0"
wrapt==1.15.0 ; python_version >= "3.9" and python_version < "4.0"