# 2012 ACS-1year sample call
url = "http://api.census.gov/data/2012/acs1/profile?get=DP02_0001PE&for=state:*&key={key}".format(key=settings.CENSUS_KEY)

import requests

r = requests.get(url)
r.content

# http://api.census.gov/data/2013/acs1/profile/variables/DP02_0001PE.json exists

requests.get("http://api.census.gov/data/2013/acs1/profile/variables/DP02_0001PE.json").json()

# 2013 ACS-1year sample call

url = "http://api.census.gov/data/2013/acs1/profile?get=DP02_0001PE&for=state:*&key={key}".format(key=settings.CENSUS_KEY)

import requests

r = requests.get(url)
r.content


# trying to get total population for 2013-1year

# http://censusreporter.org/data/table/?table=B01003&geo_ids=04000US06&primary_geo_id=04000US06
# reports 38,332,521 +/- 0

requests.get("http://api.census.gov/data/2013/acs1/variables/B01003_001E.json").json()


url = "http://api.census.gov/data/2013/acs1/profile?get=B01003_001E&for=state:*&key={key}".format(key=settings.CENSUS_KEY)
r = requests.get(url)
r.content

# how about from the following tutorial:
# http://www.digital-geography.com/many-people-live-area/#.VDrwINTF8ds

Census(settings.CENSUS_KEY, year=2012).acs.get(["B01003_001E"],{'for':'state:*'})

import json
fp = open("/Users/raymondyee/Downloads/variables_acs1_2013.json")
variables_acs1_2013 = json.load(fp)

len(variables_acs1_2013['variables'].keys())

'B01003_001E' in variables_acs1_2013['variables'].keys()

variables_acs1_2013 = json.load

# trying to get the 1-year total population for 2012 --> en route to the 2013 1-year

c.acs1dp.get('DP05_0004E', {'for': 'state:*'})

c.acs.get('B01001_004E', {'for': 'state:*'})

# age and sex
# http://censusreporter.org/data/table/?table=B01001&geo_ids=16000US0606000&primary_geo_id=16000US0606000

requests.get("http://api.census.gov/data/2013/acs1/variables/B01001_001E.json").json()

url = "http://api.census.gov/data/2013/acs1/profile?get=B01001_001E&for=state:*&key={key}".format(key=settings.CENSUS_KEY)


r = requests.get(url)
r.content

"""
Explanation: Does the census module need to be updated to accomodate Census Bureau's API Updated with 2013 ACS (1-yr) and New Features?  Maybe.  I may need to formulate URL by hand.
American Community Survey 1 Year Data --> latest, greatest:
for 2012, sample call:
http://api.census.gov/data/2012/acs1/profile?get=DP02_0001PE&for=state:*&key=...
End of explanation
"""


requests.get("http://api.census.gov/data/2013/acs1/profile/variables/DP05_0028E.json").json()

url = "http://api.census.gov/data/2013/acs1/profile?get=DP05_0028E&for=state:*&key={key}".format(key=settings.CENSUS_KEY)
r = requests.get(url)
r.json()

c.acs1dp.get('DP05_0028E', {'for': 'state:*'}, year=2013)

# how to get the total population of Berkeley, CA
# let's do Alameda County first

requests.get("http://api.census.gov/data/2013/acs1/profile?get=DP05_0028E,NAME&for=county:001&in=state:06").json()

requests.get("http://api.census.gov/data/2013/acs1/profile?get=DP05_0028E,NAME&for=place:06000&in=state:06").json()

# age
# http://censusreporter.org/profiles/16000US0606000-berkeley-ca/#age

requests.get("http://api.census.gov/data/2013/acs1/profile/variables/DP05_0004E.json").json()

r = requests.get("http://api.census.gov/data/2013/acs1/profile?get=DP05_0028E,DP05_0004E,DP05_0005E,NAME&for=place:06000&in=state:06").json()
r

from itertools import izip
d = dict(izip(r[0],r[1]))
d

# number of population 0->9

int(d[u'DP05_0004E']) + int(d[u'DP05_0004E'])

"""
Explanation: I was looking at the wrong place!!
Summary File:
API Call: http://api.census.gov/data/2013/acs1?
2013 ACS Summary File Variables [ html | xml | json ]
ACS Technical Documentation
Data Profile:
Example Call: http://api.census.gov/data/2013/acs1/profile?get=DP02_0001PE&for=state:*&key=...
2013 ACS Data Profile Variables [ html | xml | json ]
ACS Technical Documentation
End of explanation
"""


