34 lines
914 B
Python
34 lines
914 B
Python
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
import regiojet
|
|
from datetime import date, datetime, time, timedelta
|
|
import pprint
|
|
import json
|
|
from fastapi import FastAPI
|
|
app = FastAPI()
|
|
|
|
|
|
def json_serial(obj):
|
|
"""JSON serializer for objects not serializable by default json code"""
|
|
if isinstance(obj, timedelta):
|
|
return str(obj)
|
|
if isinstance(obj, (datetime, date)):
|
|
return obj.isoformat()
|
|
raise TypeError("Type %s not serializable" % type(obj))
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "Hello World"}
|
|
|
|
|
|
@app.get('/ping')
|
|
def ping():
|
|
return 'pong'
|
|
|
|
|
|
@app.get('/search')
|
|
def search(source: str, destination: str, departure_date: date, arrival_date: date):
|
|
results = regiojet.search_connection_regiojet(source, destination, 'REGULAR', 'CITY', 'CITY', departure_date, arrival_date)
|
|
pprint.pp(results)
|
|
return JSONResponse(results) |