2022-01-28 21:33:35 +11:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import urllib
|
|
|
|
import datetime
|
|
|
|
import json
|
|
|
|
import collections
|
|
|
|
|
|
|
|
import rrdtool
|
|
|
|
|
|
|
|
from weather_au import api
|
|
|
|
|
|
|
|
# Grab current temps from sensors around the house
|
|
|
|
#outside = rrdtool.fetch("/media/media/mqtt/ESP_b5952/temp/c.rrd", "AVERAGE")
|
|
|
|
#rows = outside[2][::-1]
|
|
|
|
#for data in rows:
|
|
|
|
# if data[0] is not None:
|
|
|
|
# outside_temp = data[0]
|
|
|
|
# break
|
|
|
|
outside_temp = 0
|
|
|
|
|
2022-01-29 06:54:49 +11:00
|
|
|
bedroom = rrdtool.fetch("/media/media/mqtt/ESP_b3fe20/temp.rrd", "AVERAGE")
|
2022-01-28 21:33:35 +11:00
|
|
|
rows = bedroom[2][::-1]
|
|
|
|
for data in rows:
|
|
|
|
if data[0] is not None:
|
|
|
|
bedroom_temp = int(data[0])
|
|
|
|
break
|
2022-01-29 06:54:49 +11:00
|
|
|
bedroom_temp = 0
|
2022-01-28 21:33:35 +11:00
|
|
|
|
2022-01-29 06:54:49 +11:00
|
|
|
lounge = rrdtool.fetch("/media/media/mqtt/ESP_4c7682/temp.rrd", "AVERAGE")
|
2022-01-28 21:33:35 +11:00
|
|
|
rows = lounge[2][::-1]
|
|
|
|
for data in rows:
|
|
|
|
if data[0] is not None:
|
2022-01-29 06:54:49 +11:00
|
|
|
lounge_temp = int(data[0])
|
2022-01-28 21:33:35 +11:00
|
|
|
break
|
|
|
|
|
|
|
|
bom_icons = {
|
|
|
|
'sunny': 'SUNNY.JPG',
|
|
|
|
'clear': 'CLEAR.JPG',
|
|
|
|
'partly_cloudy': 'PCLOUD.JPG',
|
2022-01-29 06:54:49 +11:00
|
|
|
'mostly_sunny': 'PCLOUD.JPG',
|
2022-01-28 21:33:35 +11:00
|
|
|
'cloudy': 'CLOUDY.JPG',
|
|
|
|
'haze': 'HAZE.JPG',
|
|
|
|
'light_rain': 'LRAIN.JPG',
|
|
|
|
'wind': 'WIND.JPG',
|
|
|
|
'fog': 'FOG.JPG',
|
|
|
|
'shower': 'SHOWER.JPG',
|
|
|
|
'rain': 'RAIN.JPG',
|
|
|
|
'dust': 'DUST.JPG',
|
|
|
|
'frost': 'FROST.JPG',
|
|
|
|
'snow': 'SNOW.JPG',
|
|
|
|
'storm': 'STORM.JPG',
|
|
|
|
'light_showers': 'LSHOWE.JPG',
|
|
|
|
'heavy_showers': 'HSHOWE.JPG',
|
|
|
|
'cyclone': 'CYCLON.JPG'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w = api.WeatherApi(search="longley+tas")
|
|
|
|
|
|
|
|
wdays_dict = w.forecasts_daily()
|
|
|
|
|
|
|
|
new = {}
|
|
|
|
weather = {}
|
|
|
|
|
|
|
|
# The first forecast period doesn't always have the temperature and other bits
|
|
|
|
# I get the overnight low and forecast to substitute when this happens.
|
|
|
|
|
2022-01-29 06:54:49 +11:00
|
|
|
if wdays_dict[0]['temp_min'] is None:
|
2022-01-28 21:33:35 +11:00
|
|
|
night = 1
|
2022-01-29 06:54:49 +11:00
|
|
|
weather['today'] = wdays_dict[0]
|
2022-01-28 21:33:35 +11:00
|
|
|
weather['tomorrow'] = wdays_dict[2]
|
|
|
|
weather['day_after'] = wdays_dict[3]
|
|
|
|
else:
|
|
|
|
night = 0
|
2022-01-29 06:54:49 +11:00
|
|
|
weather['today'] = wdays_dict[1]
|
|
|
|
weather['tomorrow'] = wdays_dict[2]
|
|
|
|
weather['day_after'] = wdays_dict[3]
|
2022-01-28 21:33:35 +11:00
|
|
|
|
|
|
|
if night:
|
|
|
|
for day in weather.keys():
|
|
|
|
new[day] = {}
|
|
|
|
if (day == 'today'):
|
|
|
|
new[day]['day'] = 'Tonight'
|
|
|
|
new[day]['max'] = weather['tomorrow']['temp_min']
|
|
|
|
new[day]['icon'] = bom_icons[weather['today']['icon_descriptor']]
|
|
|
|
else:
|
|
|
|
new[day]['day'] = datetime.datetime.strptime(weather[day]['date'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A")
|
|
|
|
new[day]['icon'] = bom_icons[weather['today']['icon_descriptor']]
|
|
|
|
new[day]['max'] = weather['today']['temp_max']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
for day in weather.keys():
|
|
|
|
new[day] = {}
|
|
|
|
new[day]['day'] = datetime.datetime.strptime(weather[day]['date'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A")
|
|
|
|
|
|
|
|
new[day]['icon'] = bom_icons[weather[day]['icon_descriptor']]
|
|
|
|
new[day]['max'] = weather[day]['temp_max']
|
|
|
|
|
|
|
|
|
|
|
|
new['current'] = {}
|
|
|
|
new['current']['outside'] = outside_temp
|
|
|
|
new['current']['bedroom'] = bedroom_temp
|
|
|
|
new['current']['lounge'] = lounge_temp
|
|
|
|
|
|
|
|
with open('bom.json', 'w') as output:
|
|
|
|
output.write(json.dumps(new))
|
|
|
|
output.close()
|