Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
13a6e1e
1
Parent(s):
b7d01c3
fix
Browse files
app/dialogflow/api/v1/dialogflow.py
CHANGED
|
@@ -7,7 +7,7 @@ from app.dialogflow.services.dialog_service import dialog_service
|
|
| 7 |
from utils.format_data_dialog import format_time, get_weekday_name
|
| 8 |
|
| 9 |
from common.external.external_api import api
|
| 10 |
-
from app.dialogflow.services.origin_codes import origin_codes
|
| 11 |
from common.response.respone_dialogflow import DialogFlowResponseAPI
|
| 12 |
router = APIRouter()
|
| 13 |
|
|
@@ -109,15 +109,15 @@ async def route(request: Request):
|
|
| 109 |
|
| 110 |
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 111 |
if origin_office:
|
| 112 |
-
|
| 113 |
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 114 |
elif raw_departure_city:
|
| 115 |
-
origin_code =
|
| 116 |
if dest_office:
|
| 117 |
-
|
| 118 |
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 119 |
elif raw_destination_city:
|
| 120 |
-
dest_code =
|
| 121 |
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 122 |
|
| 123 |
payload = {
|
|
@@ -196,15 +196,15 @@ async def price(request: Request):
|
|
| 196 |
|
| 197 |
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 198 |
if origin_office:
|
| 199 |
-
|
| 200 |
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 201 |
elif raw_departure_city:
|
| 202 |
-
origin_code =
|
| 203 |
if dest_office:
|
| 204 |
-
|
| 205 |
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 206 |
elif raw_destination_city:
|
| 207 |
-
dest_code =
|
| 208 |
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 209 |
|
| 210 |
payload = {
|
|
@@ -278,12 +278,12 @@ async def booking_trip(request: Request) -> Response:
|
|
| 278 |
origin_id, origin_code = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 279 |
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 280 |
elif raw_departure_city:
|
| 281 |
-
origin_code =
|
| 282 |
if dest_office:
|
| 283 |
dest_id, dest_code = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 284 |
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 285 |
elif raw_destination_city:
|
| 286 |
-
dest_code =
|
| 287 |
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 288 |
try:
|
| 289 |
data = await dialog_service.search_trip(from_time, to_time, route_ids, ticket_count)
|
|
|
|
| 7 |
from utils.format_data_dialog import format_time, get_weekday_name
|
| 8 |
|
| 9 |
from common.external.external_api import api
|
| 10 |
+
from app.dialogflow.services.origin_codes import origin_codes, get_origin_id_and_code
|
| 11 |
from common.response.respone_dialogflow import DialogFlowResponseAPI
|
| 12 |
router = APIRouter()
|
| 13 |
|
|
|
|
| 109 |
|
| 110 |
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 111 |
if origin_office:
|
| 112 |
+
origin_id, origin_code = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 113 |
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 114 |
elif raw_departure_city:
|
| 115 |
+
origin_id, origin_code = get_origin_id_and_code(raw_departure_city)
|
| 116 |
if dest_office:
|
| 117 |
+
dest_id, dest_code = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 118 |
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 119 |
elif raw_destination_city:
|
| 120 |
+
dest_id, dest_code = get_origin_id_and_code(raw_destination_city)
|
| 121 |
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 122 |
|
| 123 |
payload = {
|
|
|
|
| 196 |
|
| 197 |
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 198 |
if origin_office:
|
| 199 |
+
origin_id, origin_code = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 200 |
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 201 |
elif raw_departure_city:
|
| 202 |
+
origin_id, origin_code = get_origin_id_and_code(raw_departure_city)
|
| 203 |
if dest_office:
|
| 204 |
+
dest_id, dest_code = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 205 |
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 206 |
elif raw_destination_city:
|
| 207 |
+
dest_id, dest_code = get_origin_id_and_code(raw_destination_city)
|
| 208 |
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 209 |
|
| 210 |
payload = {
|
|
|
|
| 278 |
origin_id, origin_code = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 279 |
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 280 |
elif raw_departure_city:
|
| 281 |
+
origin_id, origin_code = get_origin_id_and_code(raw_departure_city)
|
| 282 |
if dest_office:
|
| 283 |
dest_id, dest_code = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 284 |
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 285 |
elif raw_destination_city:
|
| 286 |
+
dest_id, dest_code = get_origin_id_and_code(raw_destination_city)
|
| 287 |
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 288 |
try:
|
| 289 |
data = await dialog_service.search_trip(from_time, to_time, route_ids, ticket_count)
|
app/dialogflow/services/dialog_service.py
CHANGED
|
@@ -88,7 +88,6 @@ class DialogService:
|
|
| 88 |
if response.get("data"):
|
| 89 |
if response["data"].get("total") > 0:
|
| 90 |
data = response["data"]["items"]
|
| 91 |
-
print(data)
|
| 92 |
return data
|
| 93 |
except Exception as e:
|
| 94 |
print(e)
|
|
|
|
| 88 |
if response.get("data"):
|
| 89 |
if response["data"].get("total") > 0:
|
| 90 |
data = response["data"]["items"]
|
|
|
|
| 91 |
return data
|
| 92 |
except Exception as e:
|
| 93 |
print(e)
|
app/dialogflow/services/origin_codes.py
CHANGED
|
@@ -1,4 +1,13 @@
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
-
with open("static/files/
|
| 4 |
-
origin_codes = json.load(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
+
with open("static/files/origin-codes.json", "r", encoding="utf-8") as file:
|
| 4 |
+
origin_codes = json.load(file)
|
| 5 |
+
|
| 6 |
+
def get_origin_id_and_code(origin: str):
|
| 7 |
+
for x in origin_codes:
|
| 8 |
+
if x and x.get("name"):
|
| 9 |
+
if origin == x["name"]:
|
| 10 |
+
id = x["id"],
|
| 11 |
+
code = x["code"]
|
| 12 |
+
return id, code
|
| 13 |
+
return None, None
|
static/files/origin-codes.json
CHANGED
|
@@ -278,6 +278,15 @@
|
|
| 278 |
"code": "TPHCM",
|
| 279 |
"id": 31
|
| 280 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
{
|
| 282 |
"parentId": 11924,
|
| 283 |
"type": "1",
|
|
@@ -764,6 +773,15 @@
|
|
| 764 |
"code": "DALAT",
|
| 765 |
"id": 474
|
| 766 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 767 |
{
|
| 768 |
"parentId": 38,
|
| 769 |
"type": "2",
|
|
|
|
| 278 |
"code": "TPHCM",
|
| 279 |
"id": 31
|
| 280 |
},
|
| 281 |
+
{
|
| 282 |
+
"parentId": 11927,
|
| 283 |
+
"type": "1",
|
| 284 |
+
"name": "Thành phố Hồ Chí Minh",
|
| 285 |
+
"tags": "TP. Ho Chi Minh",
|
| 286 |
+
"level": 2,
|
| 287 |
+
"code": "TPHCM",
|
| 288 |
+
"id": 31
|
| 289 |
+
},
|
| 290 |
{
|
| 291 |
"parentId": 11924,
|
| 292 |
"type": "1",
|
|
|
|
| 773 |
"code": "DALAT",
|
| 774 |
"id": 474
|
| 775 |
},
|
| 776 |
+
{
|
| 777 |
+
"parentId": 38,
|
| 778 |
+
"type": "2",
|
| 779 |
+
"name": "Thành phố Đà Lạt",
|
| 780 |
+
"tags": "Da Lat",
|
| 781 |
+
"level": 3,
|
| 782 |
+
"code": "DALAT",
|
| 783 |
+
"id": 474
|
| 784 |
+
},
|
| 785 |
{
|
| 786 |
"parentId": 38,
|
| 787 |
"type": "2",
|