Created
July 1, 2010 19:23
-
-
Save onyxfish/460430 to your computer and use it in GitHub Desktop.
Fetch WeatherBug weather stations for Chicago from web.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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