new bom_rrd script using weather_au api thing
This commit is contained in:
parent
28ee53b69f
commit
f025fd6ca1
1 changed files with 107 additions and 0 deletions
107
bom_rrd2.py
Executable file
107
bom_rrd2.py
Executable file
|
@ -0,0 +1,107 @@
|
||||||
|
#!/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
|
||||||
|
|
||||||
|
bedroom = rrdtool.fetch("/media/media/mqtt/ESP_4c7682/temp.rrd", "AVERAGE")
|
||||||
|
rows = bedroom[2][::-1]
|
||||||
|
for data in rows:
|
||||||
|
if data[0] is not None:
|
||||||
|
bedroom_temp = int(data[0])
|
||||||
|
break
|
||||||
|
|
||||||
|
lounge = rrdtool.fetch("/media/media/mqtt/ESP_b3fe20/temp.rrd", "AVERAGE")
|
||||||
|
rows = lounge[2][::-1]
|
||||||
|
for data in rows:
|
||||||
|
if data[0] is not None:
|
||||||
|
lounge_temp = data[0]
|
||||||
|
break
|
||||||
|
lounge_temp = 0
|
||||||
|
|
||||||
|
bom_icons = {
|
||||||
|
'sunny': 'SUNNY.JPG',
|
||||||
|
'clear': 'CLEAR.JPG',
|
||||||
|
'partly_cloudy': 'PCLOUD.JPG',
|
||||||
|
'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 = {}
|
||||||
|
|
||||||
|
weather['today'] = wdays_dict[0]
|
||||||
|
weather['tomorrow'] = wdays_dict[1]
|
||||||
|
weather['day_after'] = wdays_dict[2]
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
if weather['today']['temp_min'] is None:
|
||||||
|
night = 1
|
||||||
|
weather['tomorrow'] = wdays_dict[2]
|
||||||
|
weather['day_after'] = wdays_dict[3]
|
||||||
|
else:
|
||||||
|
night = 0
|
||||||
|
|
||||||
|
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()
|
Loading…
Reference in a new issue