diff --git a/bom_xml.py b/bom_xml.py new file mode 100755 index 0000000..8bed4d2 --- /dev/null +++ b/bom_xml.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +import xmltodict +import urllib +import datetime +import json +import collections + +# BOM Weather XML URL for my area: +# +# see http://www.bom.gov.au/catalogue/data-feeds.shtml +# Adjust aac for your forecast region and the URL as required. + +aac = "NSW_PT254"; +bom_url = "ftp://ftp.bom.gov.au/anon/gen/fwo/IDN11060.xml"; + +bom_icons = { + '1': 'SUNNY.JPG', + '2': 'CLEAR.JPG', + '3': 'PCLOUD.JPG', + '4': 'CLOUDY.JPG', + '6': 'HAZE.JPG', + '8': 'LRAIN.JPG', + '9': 'WIND.JPG', + '10': 'FOG.JPG', + '11': 'SHOWER.JPG', + '12': 'RAIN.JPG', + '13': 'DUST.JPG', + '14': 'FROST.JPG', + '15': 'SNOW.JPG', + '16': 'STORM.JPG', + '17': 'LSHOWE.JPG', + '18': 'HSHOWE.JPG', + '19': 'CYCLON.JPG' +} + + +content = urllib.request.urlopen(bom_url) +xmldict = xmltodict.parse(content.read()) +belco = [a for a in xmldict['product']['forecast']['area'] if a['@aac'] == aac][0] + +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 + +if (type(belco['forecast-period'][0]) == type(collections.OrderedDict())): + start = 1 +else: + start = 0 + +weather['today'] = belco['forecast-period'][start] +weather['tomorrow'] = belco['forecast-period'][start+1] +weather['day_after'] = belco['forecast-period'][start+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 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() diff --git a/images/0s.jpg b/images/0s.jpg new file mode 100644 index 0000000..26230ec Binary files /dev/null and b/images/0s.jpg differ diff --git a/images/1s.jpg b/images/1s.jpg new file mode 100644 index 0000000..a4a768b Binary files /dev/null and b/images/1s.jpg differ diff --git a/images/2s.jpg b/images/2s.jpg new file mode 100644 index 0000000..cc806e0 Binary files /dev/null and b/images/2s.jpg differ diff --git a/images/3s.jpg b/images/3s.jpg new file mode 100644 index 0000000..0d4dc06 Binary files /dev/null and b/images/3s.jpg differ diff --git a/images/4s.jpg b/images/4s.jpg new file mode 100644 index 0000000..f69d897 Binary files /dev/null and b/images/4s.jpg differ diff --git a/images/5s.jpg b/images/5s.jpg new file mode 100644 index 0000000..b6fe7f3 Binary files /dev/null and b/images/5s.jpg differ diff --git a/images/6s.jpg b/images/6s.jpg new file mode 100644 index 0000000..7507e0f Binary files /dev/null and b/images/6s.jpg differ diff --git a/images/7s.jpg b/images/7s.jpg new file mode 100644 index 0000000..bae228a Binary files /dev/null and b/images/7s.jpg differ diff --git a/images/8s.jpg b/images/8s.jpg new file mode 100644 index 0000000..203db27 Binary files /dev/null and b/images/8s.jpg differ diff --git a/images/9s.jpg b/images/9s.jpg new file mode 100644 index 0000000..7edda5a Binary files /dev/null and b/images/9s.jpg differ diff --git a/images/clear.jpg b/images/clear.jpg new file mode 100644 index 0000000..264a23a Binary files /dev/null and b/images/clear.jpg differ diff --git a/images/cloudy.jpg b/images/cloudy.jpg new file mode 100644 index 0000000..3235766 Binary files /dev/null and b/images/cloudy.jpg differ diff --git a/images/cyclon.jpg b/images/cyclon.jpg new file mode 100644 index 0000000..4391690 Binary files /dev/null and b/images/cyclon.jpg differ diff --git a/images/dust.jpg b/images/dust.jpg new file mode 100644 index 0000000..d11723b Binary files /dev/null and b/images/dust.jpg differ diff --git a/images/fog.jpg b/images/fog.jpg new file mode 100644 index 0000000..1b4a226 Binary files /dev/null and b/images/fog.jpg differ diff --git a/images/frost.jpg b/images/frost.jpg new file mode 100644 index 0000000..6a3b3bd Binary files /dev/null and b/images/frost.jpg differ diff --git a/images/haze.jpg b/images/haze.jpg new file mode 100644 index 0000000..87389f8 Binary files /dev/null and b/images/haze.jpg differ diff --git a/images/hshowe.jpg b/images/hshowe.jpg new file mode 100644 index 0000000..2ebe783 Binary files /dev/null and b/images/hshowe.jpg differ diff --git a/images/lrain.jpg b/images/lrain.jpg new file mode 100644 index 0000000..d014e8a Binary files /dev/null and b/images/lrain.jpg differ diff --git a/images/lshowe.jpg b/images/lshowe.jpg new file mode 100644 index 0000000..b650d37 Binary files /dev/null and b/images/lshowe.jpg differ diff --git a/images/pcloud.jpg b/images/pcloud.jpg new file mode 100644 index 0000000..3ca4966 Binary files /dev/null and b/images/pcloud.jpg differ diff --git a/images/rain.jpg b/images/rain.jpg new file mode 100644 index 0000000..d84b21e Binary files /dev/null and b/images/rain.jpg differ diff --git a/images/shower.jpg b/images/shower.jpg new file mode 100644 index 0000000..63d3abc Binary files /dev/null and b/images/shower.jpg differ diff --git a/images/snow.jpg b/images/snow.jpg new file mode 100644 index 0000000..f694ee4 Binary files /dev/null and b/images/snow.jpg differ diff --git a/images/storm.jpg b/images/storm.jpg new file mode 100644 index 0000000..4bc58c0 Binary files /dev/null and b/images/storm.jpg differ diff --git a/images/sunny.jpg b/images/sunny.jpg new file mode 100644 index 0000000..44f5870 Binary files /dev/null and b/images/sunny.jpg differ diff --git a/images/wind.jpg b/images/wind.jpg new file mode 100644 index 0000000..b6dd53e Binary files /dev/null and b/images/wind.jpg differ