This commit is contained in:
2026-01-24 19:09:37 -05:00
parent 97ca92b945
commit 52400f888e
3 changed files with 36 additions and 46 deletions

16
app.py
View File

@@ -1,18 +1,23 @@
from flask import Flask, render_template, jsonify, request
from utils.weather import get_today_snowfall
from utils.geocode import get_city_name
from utils.weather import get_today_snowfall_async
from utils.geocode import get_city_name_async
from config import MAX_SNOW_INCHES
from flask_caching import Cache
import asyncio
app = Flask(__name__)
# Cache config: 10-minute default timeout
cache = Cache(app, config={"CACHE_TYPE": "SimpleCache", "CACHE_DEFAULT_TIMEOUT": 600})
@cache.memoize(600) # cache each request for 10 minutes
@cache.memoize()
def get_snowfall_for_location(lat, lon):
inches, snowing, tz_name = get_today_snowfall(lat, lon)
city_name = get_city_name(lat, lon)
# Run async functions in an event loop
return asyncio.run(fetch_snow_and_city(lat, lon))
async def fetch_snow_and_city(lat, lon):
inches, snowing, tz_name = await get_today_snowfall_async(lat, lon)
city_name = await get_city_name_async(lat, lon)
return inches, snowing, tz_name, city_name
@app.route("/")
@@ -43,6 +48,5 @@ def snowfall_api():
"updated": datetime.now().isoformat()
})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)