Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
ed3b063
1
Parent(s):
ff2bff1
fix service
Browse files
app/dialogflow/services/dialog_service.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from datetime import datetime
|
| 2 |
|
| 3 |
from common.external.external_api import api
|
| 4 |
|
|
@@ -7,7 +7,8 @@ class DialogService:
|
|
| 7 |
def to_datetime_from_Dialogflow(time: dict):
|
| 8 |
date_time = datetime(int(time["year"]), int(time["month"]), int(time["day"]))
|
| 9 |
return date_time
|
| 10 |
-
|
|
|
|
| 11 |
def process_dates_to_timestamp(from_time: datetime = None, to_time: datetime = None):
|
| 12 |
if to_time is None and from_time is not None:
|
| 13 |
to_time = from_time.replace(hour=23, minute=59, second=59)
|
|
@@ -18,6 +19,8 @@ class DialogService:
|
|
| 18 |
to_time = datetime.combine(today, datetime.max.time()) - timedelta(microseconds=1)
|
| 19 |
|
| 20 |
return int(from_time.timestamp()) * 1000 , int(to_time.timestamp()) * 1000
|
|
|
|
|
|
|
| 21 |
def get_param_from_dialogflow(self, body: any):
|
| 22 |
session_info = body.get("sessionInfo", {})
|
| 23 |
parameters = session_info.get("parameters", {}) if isinstance(session_info.get("parameters"), dict) else {}
|
|
@@ -30,6 +33,7 @@ class DialogService:
|
|
| 30 |
raw_time_of_day = parameters.get("time_of_day")
|
| 31 |
return raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day
|
| 32 |
|
|
|
|
| 33 |
async def search_route_ids_from_province(departure_code: str, destination_code: str):
|
| 34 |
response = await api.get(f'/metadata/office/routes?DestCode={destination_code}&OriginCode={departure_code}')
|
| 35 |
route_ids = []
|
|
@@ -37,7 +41,7 @@ class DialogService:
|
|
| 37 |
route_ids = [route.get("routeId", -1) for route in response]
|
| 38 |
return route_ids
|
| 39 |
|
| 40 |
-
|
| 41 |
async def seats_trip(route_id: int, trip_id:int, departure_date: str, departure_time: str, kind: str):
|
| 42 |
try:
|
| 43 |
params = {
|
|
|
|
| 1 |
+
from datetime import datetime, timedelta
|
| 2 |
|
| 3 |
from common.external.external_api import api
|
| 4 |
|
|
|
|
| 7 |
def to_datetime_from_Dialogflow(time: dict):
|
| 8 |
date_time = datetime(int(time["year"]), int(time["month"]), int(time["day"]))
|
| 9 |
return date_time
|
| 10 |
+
|
| 11 |
+
@staticmethod
|
| 12 |
def process_dates_to_timestamp(from_time: datetime = None, to_time: datetime = None):
|
| 13 |
if to_time is None and from_time is not None:
|
| 14 |
to_time = from_time.replace(hour=23, minute=59, second=59)
|
|
|
|
| 19 |
to_time = datetime.combine(today, datetime.max.time()) - timedelta(microseconds=1)
|
| 20 |
|
| 21 |
return int(from_time.timestamp()) * 1000 , int(to_time.timestamp()) * 1000
|
| 22 |
+
|
| 23 |
+
|
| 24 |
def get_param_from_dialogflow(self, body: any):
|
| 25 |
session_info = body.get("sessionInfo", {})
|
| 26 |
parameters = session_info.get("parameters", {}) if isinstance(session_info.get("parameters"), dict) else {}
|
|
|
|
| 33 |
raw_time_of_day = parameters.get("time_of_day")
|
| 34 |
return raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day
|
| 35 |
|
| 36 |
+
@staticmethod
|
| 37 |
async def search_route_ids_from_province(departure_code: str, destination_code: str):
|
| 38 |
response = await api.get(f'/metadata/office/routes?DestCode={destination_code}&OriginCode={departure_code}')
|
| 39 |
route_ids = []
|
|
|
|
| 41 |
route_ids = [route.get("routeId", -1) for route in response]
|
| 42 |
return route_ids
|
| 43 |
|
| 44 |
+
@staticmethod
|
| 45 |
async def seats_trip(route_id: int, trip_id:int, departure_date: str, departure_time: str, kind: str):
|
| 46 |
try:
|
| 47 |
params = {
|