Fixes for new BOM_rrd python

This commit is contained in:
Paul Warren 2022-01-30 09:41:35 +11:00
parent 89ac550635
commit 52e456f13d
1 changed files with 9 additions and 8 deletions

View File

@ -28,11 +28,11 @@ bedroom_temp = 0
lounge = rrdtool.fetch("/media/media/mqtt/ESP_4c7682/temp.rrd", "AVERAGE")
rows = lounge[2][::-1]
for data in rows:
if data[0] is not None:
lounge_temp = int(data[0])
break
try:
lounge_temp = int(rows[1][0])
except TypeError:
lounge_temp = int(rows[2][0])
bom_icons = {
'sunny': 'SUNNY.JPG',
'clear': 'CLEAR.JPG',
@ -85,8 +85,8 @@ if night:
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']
new[day]['icon'] = bom_icons[weather[day]['icon_descriptor']]
new[day]['max'] = weather[day]['temp_max']
else:
@ -103,6 +103,7 @@ new['current']['outside'] = outside_temp
new['current']['bedroom'] = bedroom_temp
new['current']['lounge'] = lounge_temp
with open('bom.json', 'w') as output:
with open('/var/www/darksky/bom.json', 'w') as output:
output.write(json.dumps(new))
output.close()