[go: up one dir, main page]

File: zcta.py

package info (click to toggle)
dict-gazetteer2k 1.0.0-5.3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 17,712 kB
  • ctags: 64
  • sloc: python: 249; makefile: 63; sh: 37
file content (23 lines) | stat: -rw-r--r-- 731 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import dictdlib, dictclient, re

rfile = open("zcta5.txt", "rt")
zctanumdict = {}

for line in rfile.xreadlines():
    line = line.strip()
    new = {}
    new['stateabbr'] = line[0:2]
    new['name'] = line[2:66].strip()
    match = re.search('^(\d\d\d\d\d )', new['name'])
    if not match:
        continue
    new['zipcode'] = int(match.group(1))
    new['population'] = int(line[66:75])
    new['housingunits'] = int(line[75:84])
    new['landarea_m'] = float(line[84:98])
    new['waterarea_m'] = float(line[98:112])
    new['landarea_mi'] = float(line[112:124])
    new['waterarea_mi'] = float(line[124:136])
    new['lat'] = float(line[136:146])
    new['long'] = float(line[146:157])
    zctanumdict[new['zipcode']] = new