moving API route to separate file

This commit is contained in:
2026-01-11 18:29:00 -07:00
parent 7b5a49979e
commit 93e6485ddf
3 changed files with 26 additions and 13 deletions

22
weather/api.py Normal file
View File

@@ -0,0 +1,22 @@
from flask import (
Blueprint
)
from werkzeug.exceptions import abort
from weather.db import get_db
bp = Blueprint('api', __name__)
@bp.route('/api')
def api():
db = get_db()
latest_period = dict(db.execute(
'SELECT `id` FROM `reports` WHERE `type` = "hourly" ORDER BY `reported_at` DESC'
).fetchone())
current_conditions = dict(db.execute(
f"SELECT * FROM `periods` WHERE `report_id` = {latest_period['id']} LIMIT 1"
).fetchone())
return current_conditions