Browse files

remove census.states module and now require us package

  • Loading branch information...
1 parent ec13319 commit 0913912fd77e322a0e59ec6ac8219014ab2c6ca1 @jcarbaugh jcarbaugh committed Aug 15, 2012
Showing with 18 additions and 81 deletions.
  1. +15 −14 README.rst
  2. +0 −65 census/states.py
  3. +1 −0 requirements.txt
  4. +2 −2 setup.py
View
29 README.rst
@@ -12,6 +12,7 @@ Requirements
* python 2.6 or 2.7
* requests
+* us
Usage
@@ -21,16 +22,17 @@ First, get yourself a `Census API key <http://www.census.gov/developers/>`_.
::
- from census import Census, states
+ from census import Census
+ from us import states
c = Census("MY_API_KEY")
- c.acs.get(('NAME', 'B25034_010E'), {'for': 'state:%s' % states.MD})
+ c.acs.get(('NAME', 'B25034_010E'), {'for': 'state:%s' % states.MD.fips})
The call above will return the name of the geographic area and the number of
homes that were built before 1939 for the state of Maryland. Helper methods have
been created to simplify common geometry calls::
- c.acs.state(('NAME', 'B25034_010E'), states.MD)
+ c.acs.state(('NAME', 'B25034_010E'), states.MD.fips)
Full details on geometries and the states module can be found below.
@@ -85,30 +87,29 @@ SF1 Geometries
States
======
-The states module makes it easy to convert between state abbreviations and FIPS
-codes. Access attributes by state abbreviation to get the corresponding FIPS
-code::
+This package previously had a `census.states` module, but now uses the
+*us* package. ::
- >>> from census import states
- >>> print states.MD
- 24
+ >>> from us import states
+ >>> print states.MD.fips
+ u'24'
-Convert FIPS to state abbreviation using the FIPS dict::
+Convert FIPS to state abbreviation using `lookup()`: ::
- >>> print states.FIPS['24']
- MD
+ >>> print states.lookup('24').abbr
+ u'MD'
Examples
========
The geographic name for all census tracts for county 170 in Alaska::
- c.sf1.get('NAME', geo={'for': 'tract:*', 'in': 'state:%s county:170' % states.AK})
+ c.sf1.get('NAME', geo={'for': 'tract:*', 'in': 'state:%s county:170' % states.AK.fips})
The same call using the `state_county_tract` convenience method::
- c.sf1.state_county_tract('NAME', states.AK, '170', Census.ALL)
+ c.sf1.state_county_tract('NAME', states.AK.fips, '170', Census.ALL)
Total number of males age 5 - 9 for all states::
View
65 census/states.py
@@ -1,65 +0,0 @@
-STATES = {
- 'AK': '02',
- 'AL': '01',
- 'AR': '05',
- 'AS': '60',
- 'AZ': '04',
- 'CA': '06',
- 'CO': '08',
- 'CT': '09',
- 'DC': '11',
- 'DE': '10',
- 'FL': '12',
- 'GA': '13',
- 'GU': '66',
- 'HI': '15',
- 'IA': '19',
- 'ID': '16',
- 'IL': '17',
- 'IN': '18',
- 'KS': '20',
- 'KY': '21',
- 'LA': '22',
- 'MA': '25',
- 'MD': '24',
- 'ME': '23',
- 'MI': '26',
- 'MN': '27',
- 'MO': '29',
- 'MS': '28',
- 'MT': '30',
- 'NC': '37',
- 'ND': '38',
- 'NE': '31',
- 'NH': '33',
- 'NJ': '34',
- 'NM': '35',
- 'NV': '32',
- 'NY': '36',
- 'OH': '39',
- 'OK': '40',
- 'OR': '41',
- 'PA': '42',
- 'PR': '72',
- 'RI': '44',
- 'SC': '45',
- 'SD': '46',
- 'TN': '47',
- 'TX': '48',
- 'UT': '49',
- 'VA': '51',
- 'VI': '78',
- 'VT': '50',
- 'WA': '53',
- 'WI': '55',
- 'WV': '54',
- 'WY': '56',
-}
-
-FIPS = {v: k for (k, v) in STATES.items()}
-
-""" What I really want to be able to do is states.MD to get the FIPS code.
- This will set each k, v of STATES as a module attribute.
-"""
-for (s, f) in STATES.items():
- globals()[s] = f
View
1 requirements.txt
@@ -1 +1,2 @@
requests
+us==0.3
View
4 setup.py
@@ -4,7 +4,7 @@
setup(
name="census",
- version='0.2',
+ version='0.3',
py_modules=['census'],
author="Jeremy Carbaugh",
author_email='jcarbaugh@sunlightfoundation.com',
@@ -22,5 +22,5 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
],
- install_requires=['requests'],
+ install_requires=['requests', 'us'],
)

0 comments on commit 0913912

Please sign in to comment.