File size: 1,184 Bytes
a842ea6
 
 
621bc07
a842ea6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e12aff8
a842ea6
 
 
 
7157a06
 
a842ea6
7157a06
a842ea6
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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


class UserData(BaseModel):
    user_Name: str
    user_ID: int
    platforms: Platforms


class InputData(BaseModel):
    data: List[UserData]


@app.post("/get")
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))