forked from gkipkorir/cs465_final_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.py
35 lines (22 loc) · 969 Bytes
/
get_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# import requests
# resp = requests.get("http://api.census.gov/data/timeseries/healthins/sahie?get=NIC_PT,NAME,NUI_PT&for=us:*&time=2013&key=e0103f837daffd400e2208bacbf97de2be035383")
# if resp.status_code != 200:
# print "Error! Request not successful"
# print resp.json
import urllib2
import json
# req = urllib2.Request("http://api.census.gov/data/timeseries/healthins/sahie?get=NIC_PT,NAME,NUI_PT&for=us:*&time=2013&key=e0103f837daffd400e2208bacbf97de2be035383")
# response = urllib2.urlopen(req)
# the_page = response.read()
# print response.json
# #print the_page
startYear = 2006
endYear = 2013
myData = []
for year in range(startYear, endYear+1):
url = "http://api.census.gov/data/timeseries/healthins/sahie?get=NIC_PT,NAME,NUI_PT&for=STATE:025&time=" + str(year)
yearData = json.load(urllib2.urlopen(url))
myData.append({year: yearData})
output_name = "yearly_data.txt"
with open(output_name, 'w') as outfile:
json.dump(myData, outfile)