Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions census/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,87 @@ def state_zipcode(self, fields, state_fips, zcta, **kwargs):
'in': 'state:{}'.format(state_fips),
}, **kwargs)

class SF3Client(Client):

default_year = 2010
dataset = 'sf3'

years = (2010,)

def _switch_endpoints(self, year):

self.endpoint_url = 'https://api.census.gov/data/%s/dec/%s'
self.definitions_url = 'https://api.census.gov/data/%s/dec/%s/variables.json'
self.definition_url = 'https://api.census.gov/data/%s/dec/%s/variables/%s.json'
self.groups_url = 'https://api.census.gov/data/%s/dec/%s/groups.json'

def tables(self, *args, **kwargs):
self._switch_endpoints(kwargs.get('year', self.default_year))
return super(SF3Client, self).tables(*args, **kwargs)

def get(self, *args, **kwargs):
self._switch_endpoints(kwargs.get('year', self.default_year))

return super(SF3Client, self).get(*args, **kwargs)

@supported_years()
def state_county_subdivision(self, fields, state_fips,
county_fips, subdiv_fips, **kwargs):
return self.get(fields, geo={
'for': 'county subdivision:{}'.format(subdiv_fips),
'in': 'state:{} county:{}'.format(state_fips, county_fips),
}, **kwargs)

@supported_years()
def state_county_tract(self, fields, state_fips,
county_fips, tract, **kwargs):
return self.get(fields, geo={
'for': 'tract:{}'.format(tract),
'in': 'state:{} county:{}'.format(state_fips, county_fips),
}, **kwargs)

@supported_years()
def state_county_blockgroup(self, fields, state_fips, county_fips,
blockgroup, tract=None, **kwargs):
geo = {
'for': 'block group:{}'.format(blockgroup),
'in': 'state:{} county:{}'.format(state_fips, county_fips),
}
if tract:
geo['in'] += ' tract:{}'.format(tract)
return self.get(fields, geo=geo, **kwargs)

@supported_years(2010)
def state_msa(self, fields, state_fips, msa, **kwargs):
return self.get(fields, geo={
'for': ('metropolitan statistical area/' +
'micropolitan statistical area (or part):{}'.format(msa)),
'in': 'state:{}'.format(state_fips),
}, **kwargs)

@supported_years(2010)
def state_csa(self, fields, state_fips, csa, **kwargs):
return self.get(fields, geo={
'for': 'combined statistical area (or part):{}'.format(csa),
'in': 'state:{}'.format(state_fips),
}, **kwargs)

@supported_years(2010)
def state_district_place(self, fields, state_fips,
district, place, **kwargs):
return self.get(fields, geo={
'for': 'place/remainder (or part):{}'.format(place),
'in': 'state:{} congressional district:{}'.format(
state_fips, district),
}, **kwargs)

@supported_years(2010)
def state_zipcode(self, fields, state_fips, zcta, **kwargs):
return self.get(fields, geo={
'for': 'zip code tabulation area (or part):{}'.format(zcta),
'in': 'state:{}'.format(state_fips),
}, **kwargs)


class PLClient(Client):

Expand Down Expand Up @@ -588,6 +669,7 @@ def __init__(self, key, year=None, session=None):
self.acs3dp = ACS3DpClient(key, year, session)
self.acs1dp = ACS1DpClient(key, year, session)
self.sf1 = SF1Client(key, year, session)
self.sf3 = SF3Client(key, year, session)
self.pl = PLClient(key, year, session)

@property
Expand Down