-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (23 loc) · 783 Bytes
/
main.py
File metadata and controls
33 lines (23 loc) · 783 Bytes
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
import json
from os.path import dirname, abspath, join
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
current_dir = dirname(abspath(__file__))
historical_data = join(current_dir, "weather.json")
app = FastAPI()
# load historical json data and serialize it:
with open(historical_data, "r") as f:
data = json.load(f)
@app.get('/')
def root():
"""
Allows to open the API documentation in the browser directly instead of
requiring to open the /docs path.
"""
return RedirectResponse(url='/docs', status_code=301)
@app.get('/countries')
def countries():
return list(data.keys())
@app.get('/countries/{country}/{city}/{month}')
def monthly_average(country: str, city: str, month: str):
return data[country][city][month]