Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, HTTPException, Header | |
| from pydantic import BaseModel | |
| from typing import List | |
| from searcher import user_Urls | |
| app = FastAPI() | |
| user_Agent = user_Urls() | |
| class Platforms(BaseModel): | |
| booking: bool | |
| tripadvisor: bool | |
| hotels: bool | |
| agoda: bool | |
| expedia: bool | |
| holidaycheck: bool | |
| class UserData(BaseModel): | |
| user_Name: str | |
| user_ID: int | |
| platforms: Platforms | |
| class InputData(BaseModel): | |
| data: List[UserData] | |
| async def run_script(input_Data: InputData, token: str = Header(None, alias="api-token")): | |
| try: | |
| if token: | |
| if input_Data.data: | |
| res = user_Agent.get_Search_Results(input_Data.data, token) | |
| if res: | |
| return {"status": 200, "data": res} | |
| else: | |
| raise HTTPException(status_code=500, detail="The request can not be fulfilled") | |
| else: | |
| raise HTTPException(status_code=400, detail="the input format is uncorrect") | |
| else: | |
| raise HTTPException(status_code=400, detail="Missing 'api-token'.") | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) |