diff --git a/antithesize/weather-api-wrapper.zip b/antithesize/weather-api-wrapper.zip new file mode 100644 index 0000000..25d9f3b Binary files /dev/null and b/antithesize/weather-api-wrapper.zip differ diff --git a/main.py b/main.py index 38a6e74..a07e423 100644 --- a/main.py +++ b/main.py @@ -151,6 +151,37 @@ async def get_weather_ui(request: Request, city: str, db: Session = Depends(get_ "timestamp": db_weather.timestamp }) +@app.get("/featured/weather/ui/{city}", response_class=HTMLResponse) +async def get_weather_ui(request: Request, city: str, db: Session = Depends(get_db)): + weather = await services.fetch_weather(city) + + if not weather: + db_weather = models.WeatherHistory( + city=city, + temperature=None, + description="not found" + ) + db.add(db_weather) + db.commit() + db.refresh(db_weather) + else: + db_weather = models.WeatherHistory( + city=city, + temperature=weather["temperature"], + description=weather["description"] + ) + db.add(db_weather) + db.commit() + db.refresh(db_weather) + + return templates.TemplateResponse("featured_city_weather.html", { + "request": request, + "city": db_weather.city, + "temperature": db_weather.temperature, + "description": db_weather.description, + "timestamp": db_weather.timestamp + }) + @app.get("/history", response_model=List[schemas.WeatherResponse]) def get_history(db: Session = Depends(get_db)): @@ -193,3 +224,8 @@ def delete_history(record_id: int, db: Session = Depends(get_db)): def get_cities_ui(request: Request, db: Session = Depends(get_db)): cities = db.query(models.WeatherHistory).all() return templates.TemplateResponse("cities.html", {"request": request, "cities": cities}) + + +if __name__ == "__main__": + import uvicorn + uvicorn.run(app, host="127.0.0.1", port=5500) diff --git a/templates/featured_city_weather.html b/templates/featured_city_weather.html new file mode 100644 index 0000000..7f4bbdb --- /dev/null +++ b/templates/featured_city_weather.html @@ -0,0 +1,20 @@ + + + + Weather in {{ city }} + + + +

🌤 Weather Report

+
+

{{ city }}

+

Temperature: {{ temperature or "N/A" }}

+

Description: {{ description }}

+

{{ timestamp }}

+
+ + diff --git a/templates/index.html b/templates/index.html index 3f3d170..f303b9b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -65,7 +65,7 @@

🌤 Weather API

🌟 Featured City: Lagos

- +