Skip to content

Instantly share code, notes, and snippets.

@onyxfish
Created July 1, 2010 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save onyxfish/460430 to your computer and use it in GitHub Desktop.
Save onyxfish/460430 to your computer and use it in GitHub Desktop.
Fetch WeatherBug weather stations for Chicago from web.
#!/bin/env python
import csv
import re
from urllib2 import urlopen
from BeautifulSoup import BeautifulStoneSoup
WEATHERBUG_API_KEY = 'A6464697672'
WEATHERBUG_SEARCH_URL = 'http://api.wxbug.net/getStationsXML.aspx?ACode=' + WEATHERBUG_API_KEY + '&zipCode=60601&unittype=0'
list_xml = urlopen(WEATHERBUG_SEARCH_URL)
list_soup = BeautifulStoneSoup(list_xml.read())
station_tags = list_soup.findAll('aws:station')
station_data = []
for tag in station_tags:
station_id = tag['id']
name = tag['name']
latitude = tag['latitude']
longitude = tag['longitude']
station_data.append((station_id, name, '%s %s' % (latitude, longitude), 'WeatherBug'))
print 'Got ', station_id
output = csv.writer(open("weatherbug_station_data.csv", "wb"))
output.writerows([('station_id', 'name', 'location', 'source')])
output.writerows(station_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment