Created
May 28, 2015 22:54
-
-
Save thequbit/fe5dcc22a1727e40fb5e to your computer and use it in GitHub Desktop.
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
import urllib2 | |
import json | |
from bs4 import BeautifulSoup | |
def get_station_info(index, api_key): | |
try: | |
url = "http://api.npr.org/v2/stations/org/{0}?apiKey={1}".format(index, api_key) | |
content = urllib2.urlopen(url).read() | |
except Exception, ex: | |
print "ERROR: {0}".format(ex) | |
content = None | |
return content | |
def get_all_stations_info(start, end, api_key): | |
stations = [] | |
for i in range(start, end+1): | |
stations.append(get_station_info(i, api_key)) | |
return stations | |
if __name__ == '__main__': | |
print "Starting ..." | |
stations = get_all_stations_info(1, 896, 'mah_super_duper_key') | |
with open('stations.json', 'w') as f: | |
f.write(json.dumps(stations)) | |
print "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment