adding day/night to background images, added some more conditions
|
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
BIN
weather/static/images/day_cloudy.jpg
Normal file
|
After Width: | Height: | Size: 2.4 MiB |
1
weather/static/images/day_cloudy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/kapa65-61253/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1494656">Karsten Paulick</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1494656">Pixabay</a>
|
||||
BIN
weather/static/images/day_rainy.jpg
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
1
weather/static/images/day_rainy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/diego_torres-1118992/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=815271">Roman Grac</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=815271">Pixabay</a>
|
||||
BIN
weather/static/images/day_snowy.jpg
Normal file
|
After Width: | Height: | Size: 2.4 MiB |
1
weather/static/images/day_snowy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/juncala-5111596/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=7661769">Juncala</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=7661769">Pixabay</a>
|
||||
BIN
weather/static/images/day_stormy.jpg
Normal file
|
After Width: | Height: | Size: 627 KiB |
1
weather/static/images/day_stormy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/sethink-348886/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=399853">sethink</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=399853">Pixabay</a>
|
||||
BIN
weather/static/images/night_clear.jpg
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
1
weather/static/images/night_clear_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/medienservice-1888061/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=6558014">Nicole Pankalla</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=6558014">Pixabay</a>
|
||||
BIN
weather/static/images/night_cloudy.jpg
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
1
weather/static/images/night_cloudy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/pexels-2286921/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1869753">Pexels</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1869753">Pixabay</a>
|
||||
BIN
weather/static/images/night_rainy.jpg
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
1
weather/static/images/night_rainy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/photos/night-lighting-road-light-rain-777882/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1869753">Pexels</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1869753">Pixabay</a>
|
||||
BIN
weather/static/images/night_snowy.jpg
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
1
weather/static/images/night_snowy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/jerzygórecki-2233926/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=3373432">Jerzy</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=3373432">Pixabay</a>
|
||||
BIN
weather/static/images/night_stormy.jpg
Normal file
|
After Width: | Height: | Size: 548 KiB |
1
weather/static/images/night_stormy_license.html
Normal file
@@ -0,0 +1 @@
|
||||
Image by <a href="https://pixabay.com/users/oimheidi-1660138/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1455285">Claudia Hinz</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1455285">Pixabay</a>
|
||||
@@ -2,6 +2,7 @@ from flask import (
|
||||
Blueprint, render_template
|
||||
)
|
||||
from werkzeug.exceptions import abort
|
||||
from datetime import datetime
|
||||
|
||||
from weather.db import get_db
|
||||
|
||||
@@ -10,20 +11,26 @@ 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'
|
||||
current_conditions = dict(db.execute(
|
||||
f"SELECT * FROM `reports` WHERE `type` = 'hourly' ORDER BY `end_time` DESC LIMIT 1"
|
||||
).fetchone())
|
||||
|
||||
current_conditions = dict(db.execute(
|
||||
f"SELECT * FROM `periods` WHERE `report_id` = {latest_period['id']} LIMIT 1"
|
||||
).fetchone())
|
||||
stale_datetime = datetime.strptime(current_conditions['end_time'], "%Y-%m-%d %H:%M:%S")
|
||||
if datetime.now() > stale_datetime:
|
||||
# fetch new data
|
||||
# save new data
|
||||
|
||||
# TODO: add conditions to check for day/night
|
||||
condition_image = f"images/{current_conditions['short_forecast'].lower()}.jpg"
|
||||
day_or_night = 'day'
|
||||
if current_conditions['is_daytime']:
|
||||
day_or_night = 'night'
|
||||
|
||||
periods = db.execute(
|
||||
condition = mapForecastToImage(current_conditions['short_forecast'])
|
||||
condition_image = f"images/{time_of_day}_{condition}.jpg"
|
||||
|
||||
hourly_reports = db.execute(
|
||||
'SELECT *'
|
||||
' FROM `periods`'
|
||||
' FROM `reports`'
|
||||
' ORDER BY `id` DESC'
|
||||
' LIMIT 7'
|
||||
).fetchall()
|
||||
@@ -35,3 +42,25 @@ def index():
|
||||
periods=periods
|
||||
)
|
||||
|
||||
def mapForecastToImage(condition: str):
|
||||
if not condition:
|
||||
return 'cloudy'
|
||||
|
||||
condition = condition.lower()
|
||||
if 'thunder' in condition or 'storm' in condition:
|
||||
return 'stormy'
|
||||
elif 'snow' in condition:
|
||||
return 'snowy'
|
||||
elif 'rain' in condition or 'shower' in condition or 'drizzle' in condition:
|
||||
return 'rainy'
|
||||
elif 'wind' in condition:
|
||||
return 'windy'
|
||||
elif 'sunny' in condition or 'clear' in condition:
|
||||
return 'sunny'
|
||||
elif 'cloud' in condition or 'overcast' in condition:
|
||||
return 'cloudy'
|
||||
elif 'fog' in condition or 'mist' in condition:
|
||||
return 'cloudy'
|
||||
else:
|
||||
return 'cloudy'
|
||||
|
||||
|
||||