Missed date, and use the proper icon!
This commit is contained in:
parent
455379986e
commit
cc126550f2
1 changed files with 38 additions and 18 deletions
56
bom_xml.py
56
bom_xml.py
|
@ -44,30 +44,50 @@ 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] = {}
|
if night:
|
||||||
new[day]['day'] = datetime.datetime.strptime(weather[day]['@start-time-local'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A")
|
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']:
|
for el in weather[day]['element']:
|
||||||
if type(el) == type(collections.OrderedDict()):
|
if type(el) == type(collections.OrderedDict()):
|
||||||
if el['@type'] == "forecast_icon_code":
|
if el['@type'] == "forecast_icon_code":
|
||||||
new[day]['icon'] = bom_icons[el['#text']]
|
new[day]['icon'] = bom_icons[el['#text']]
|
||||||
elif el['@type'] == 'air_temperature_maximum':
|
elif el['@type'] == 'air_temperature_maximum':
|
||||||
new[day]['max'] = el['#text']
|
new[day]['max'] = el['#text']
|
||||||
|
|
||||||
|
|
||||||
with open('bom.json', 'w') as output:
|
with open('bom.json', 'w') as output:
|
||||||
output.write(json.dumps(new))
|
output.write(json.dumps(new))
|
||||||
output.close()
|
output.close()
|
||||||
|
|
Loading…
Reference in a new issue