Files
flask-weather/weather/weather.py

38 lines
949 B
Python

from flask import (
Blueprint, render_template
)
from werkzeug.exceptions import abort
from weather.db import get_db
bp = Blueprint('weather', __name__)
@bp.route('/')
def index():
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())
# TODO: add conditions to check for day/night
condition_image = f"images/{current_conditions['short_forecast'].lower()}.jpg"
periods = db.execute(
'SELECT *'
' FROM `periods`'
' ORDER BY `id` DESC'
' LIMIT 7'
).fetchall()
return render_template(
'weather/index.html',
current_conditions=current_conditions,
condition_image=condition_image,
periods=periods
)