Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles


current_dir = dirname(abspath(__file__))
wellknown_path = join(current_dir, ".well-known")
historical_data = join(current_dir, "weather.json")
Expand Down Expand Up @@ -38,4 +37,13 @@ def monthly_average(country: str, city: str, month: str):
# Generate the OpenAPI schema:
openapi_schema = app.openapi()
with open(join(wellknown_path, "openapi.json"), "w") as f:
json.dump(openapi_schema, f)
json.dump(openapi_schema, f)

@app.get('/countries/{country}/cities')
def cities(country: str):
"""
Returns a list of cities for a given country.
"""
if country not in data:
return {"error": f"Country '{country}' not found."}
return list(data[country].keys())