diff --git a/census/core.py b/census/core.py index 14cbfe5..0e537d4 100644 --- a/census/core.py +++ b/census/core.py @@ -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): @@ -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