a terrible but somewhat functional state
This commit is contained in:
@@ -10,9 +10,40 @@ 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', periods=periods)
|
||||
|
||||
return render_template(
|
||||
'weather/index.html',
|
||||
current_conditions=current_conditions,
|
||||
condition_image=condition_image,
|
||||
periods=periods
|
||||
)
|
||||
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user