-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (32 loc) · 1.05 KB
/
main.py
File metadata and controls
41 lines (32 loc) · 1.05 KB
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
from fastapi import FastAPI
from fastapi.responses import Response
import requests
from dotenv import dotenv_values, load_dotenv
load_dotenv()
app = FastAPI()
url = "http://localhost:8080/"
BEARER_TOKEN = dotenv_values(".env")
headers = {
"Authorization": f"Bearer {BEARER_TOKEN}",
"Content-Type": "application/json"
}
if BEARER_TOKEN is None or BEARER_TOKEN == "":
raise ValueError("Bearer token is not set in the .env file.")
@app.get("/prompt")
def get_data():
countries = requests.get(url + f"/countries")
pandemics = requests.get(url + f"/pandemics")
infections = requests.get(url + f"/infections")
reports = requests.get(url + f"/repors")
if countries.status_code != 200 or \
pandemics.status_code != 200 or \
infections.status_code != 200 or \
reports.status_code != 200:
return Response(status_code=500)
response = {
"countries": countries.json(),
"pandemics": pandemics.json(),
"infections": infections.json(),
"reports": reports.json()
}
return response