Skip to content
Open
Show file tree
Hide file tree
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
Binary file added antithesize/weather-api-wrapper.zip
Binary file not shown.
36 changes: 36 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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)
20 changes: 20 additions & 0 deletions templates/featured_city_weather.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Weather in {{ city }}</title>
<style>
body { font-family: Arial, sans-serif; margin: 2rem; background: #f0f9ff; color: #111827; }
h1 { color: #1d4ed8; }
.card { background: white; padding: 1.5rem; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); width: 300px; }
</style>
</head>
<body>
<h1>🌤 Weather Report</h1>
<div class="card">
<h2>{{ city }}</h2>
<p><strong>Temperature:</strong> {{ temperature or "N/A" }}</p>
<p><strong>Description:</strong> {{ description }}</p>
<p><small>{{ timestamp }}</small></p>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1>🌤 Weather API</h1>

<!-- Featured Weather -->
<h2>🌟 Featured City: Lagos</h2>
<iframe src="/weather/ui/Lagos" style="width:100%; height:300px; border:none; border-radius:8px; background:white;"></iframe>
<iframe src="/featured/weather/ui/Lagos" style="width:100%; height:300px; border:none; border-radius:8px; background:white;"></iframe>

<!-- Footer -->
<footer>
Expand Down
5 changes: 5 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ def test_delete_records():
delete_response = client.delete(f"/history/{record_id}")
assert delete_response.status_code == 200
assert delete_response.json() == {"message": f"Record {record_id} Deleted successfully"}


if __name__ == "__main__":
pytest.main()

Binary file modified weather.db
Binary file not shown.