Created
May 7, 2010 01:32
-
-
Save mtigas/392914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See http://www.census.gov/tiger/tms/gazetteer/zips.txt | |
import csv | |
from places.models import ZipCode | |
from django.contrib.gis.geos import fromstr as geo_from_str | |
state_cache = dict() | |
reader = csv.reader(open('zips.txt'),delimiter=',',quotechar='"') | |
for row in reader: | |
z,created = None,False | |
if not state_cache.has_key(row[2]): | |
state_cache[row[2]] = State.objects.get(abbr=row[2]) | |
z,created = ZipCode.objects.get_or_create( | |
zip_id=int(row[1]), | |
defaults = { | |
'state':state_cache[row[2]], | |
'location':geo_from_str("POINT(-%s %s)" % (row[4],row[5])) | |
} | |
) | |
if created: | |
z.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment