Missed date, and use the proper icon!

This commit is contained in:
Paul Warren 2019-11-27 18:34:17 +11:00
parent 455379986e
commit cc126550f2
1 changed files with 38 additions and 18 deletions

View File

@ -44,30 +44,50 @@ new = {}
#current = a['forecast-period'][0]
weather = {}
# THe first forecast perios doesn't always have the temperature and other bits
# I chose to just switch to tomorrow
# 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 (type(belco['forecast-period'][0]) == type(collections.OrderedDict())):
start = 1
night = 1
else:
start = 0
night = 0
weather['today'] = belco['forecast-period'][start]
weather['tomorrow'] = belco['forecast-period'][start+1]
weather['day_after'] = belco['forecast-period'][start+2]
weather['today'] = belco['forecast-period'][0]
weather['tomorrow'] = belco['forecast-period'][1]
weather['day_after'] = belco['forecast-period'][2]
for day in weather.keys():
new[day] = {}
new[day]['day'] = datetime.datetime.strptime(weather[day]['@start-time-local'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A")
if night:
for day in weather.keys():
new[day] = {}
if (day == 'today'):
new[day]['day'] = 'Tonight'
new[day]['max'] = [a for a in weather['tomorrow']['element'] if a['@type'] == 'air_temperature_minimum'][0]['#text']
new[day]['icon'] = bom_icons[weather['today']['element']['#text']]
#bom_icons[[a for a in weather['tomorrow']['element'] if a['@type'] == 'forecast_icon_code'][0]['#text']]
else:
new[day]['day'] = datetime.datetime.strptime(weather[day]['@start-time-local'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A")
for el in weather[day]['element']:
if type(el) == type(collections.OrderedDict()):
if el['@type'] == "forecast_icon_code":
new[day]['icon'] = bom_icons[el['#text']]
elif el['@type'] == 'air_temperature_maximum':
new[day]['max'] = el['#text']
else:
for day in weather.keys():
new[day] = {}
new[day]['day'] = datetime.datetime.strptime(weather[day]['@start-time-local'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A")
for el in weather[day]['element']:
if type(el) == type(collections.OrderedDict()):
if el['@type'] == "forecast_icon_code":
new[day]['icon'] = bom_icons[el['#text']]
elif el['@type'] == 'air_temperature_maximum':
new[day]['max'] = el['#text']
for el in weather[day]['element']:
if type(el) == type(collections.OrderedDict()):
if el['@type'] == "forecast_icon_code":
new[day]['icon'] = bom_icons[el['#text']]
elif el['@type'] == 'air_temperature_maximum':
new[day]['max'] = el['#text']
with open('bom.json', 'w') as output:
output.write(json.dumps(new))
output.close()