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