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

View file

@ -44,28 +44,48 @@ new = {}
#current = a['forecast-period'][0] #current = a['forecast-period'][0]
weather = {} weather = {}
# THe first forecast perios doesn't always have the temperature and other bits # The first forecast period doesn't always have the temperature and other bits
# I chose to just switch to tomorrow # I get the overnight low and forecast to substitute when this happens.
if (type(belco['forecast-period'][0]) == type(collections.OrderedDict())): if (type(belco['forecast-period'][0]) == type(collections.OrderedDict())):
start = 1 night = 1
else: else:
start = 0 night = 0
weather['today'] = belco['forecast-period'][start] weather['today'] = belco['forecast-period'][0]
weather['tomorrow'] = belco['forecast-period'][start+1] weather['tomorrow'] = belco['forecast-period'][1]
weather['day_after'] = belco['forecast-period'][start+2] 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")
for el in weather[day]['element']: if night:
if type(el) == type(collections.OrderedDict()): for day in weather.keys():
if el['@type'] == "forecast_icon_code": new[day] = {}
new[day]['icon'] = bom_icons[el['#text']] if (day == 'today'):
elif el['@type'] == 'air_temperature_maximum': new[day]['day'] = 'Tonight'
new[day]['max'] = el['#text'] 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']
with open('bom.json', 'w') as output: with open('bom.json', 'w') as output: