Task 4, API
This commit is contained in:
34
regioget_api.py
Normal file
34
regioget_api.py
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user