Reading Airport Weather Data
Posted: Mon Mar 28, 2016 11:36 am
As I live in a compact urban area, so I haven't bothered putting up a proper rain gauge, or wind sensors. There is a BOM weather station around 2km from my house, so I usually just look up the BOM webpage to see the current wind/rain data. I have been meaning to script up something to automate the data collection so I can store the data in my local weather station MySQL database. The last few days of rain was the final straw, so late one evening (while the rain was drizzling on), with a bit of Googling I fumbled together some a few python json statements to list out the data that I wanted to collect, then later I add on a some MySQL lines to store the data safely away.
Here is the JSON demo part:
Some useful URL's:
Here is the JSON demo part:
Code: Select all
import json
import requests
# set local variables
count = 0
index = 0
# go get the BOM weather data, as a json data file
r = requests.get('http://www.bom.gov.au/fwo/IDW60801/IDW60801.95611.json')
#print r.status_code
#print r.text
#print r.headers
#print r.url
data = json.loads(r.text)
# count the number of data rows we have downloaded
count = len(data["observations"]["data"])
print "number of current data events", count
# read airport weather
for index in range(0, count):
url_datetime = data["observations"]["data"][index]["local_date_time_full"]
wind_gust = data["observations"]["data"][index]["gust_kmh"]
wind_speed = data["observations"]["data"][index]["wind_spd_kmh"]
wind_dir = data["observations"]["data"][index]["wind_dir"]
air_temp = data["observations"]["data"][index]["air_temp"]
air_press = data["observations"]["data"][index]["press"]
humid = data["observations"]["data"][index]["rel_hum"]
rain = data["observations"]["data"][index]["rain_trace"]
# read out the data
print url_datetime, air_temp, wind_dir, wind_speed, wind_gust, humid, rain
print 'end'
exit()
Some useful URL's:
- http://www.python-requests.org/en/lates ... se-content ; response website
- https://docs.python.org/2/library/json.html ; json web info
- http://www.bom.gov.au/fwo/IDW60801/IDW60801.95611.json ; BSN airport weather data: json encoded
- http://www.bom.gov.au/products/IDW60801 ... 5611.shtml ; BSN airport weather data in a human readable format