python crash problem
Yelena
yelena.mqw at gmail.com
Wed Feb 2 14:21:15 EST 2011
Here is the code, I edited out some private info:
import sys
import urllib2
import string
import re
import datetime
from mx import DateTime
from dbfpy import dbf
addylist = ['add.dbf']
okset = ['P','L','I','B']
for addy in addylist:
db = dbf.Dbf(addy)
print (addy)
count = len(db)
db.close()
del db
foo = ((0, 1000),(1000,count/3), (count/3, count/3*2), (count/3*2,
count))
for (start,finish) in foo:
ab = dbf.Dbf(addy)
for x in range(start, finish):
print x
rec = ab[x]
if rec["flag"] in [1,3]:
INP_info = rec["address"] + " " + rec["city"] + " "
+rec["state"] + " " + rec["zip"]
INP_info = INP_info.replace(' ',',')
HOST_URL = '***'
KEY = '***'
STD_URL = '***'
STD_URL = STD_URL.replace('location=','location=' +
INP_info)
STD_URL = STD_URL.replace('key=','key=' + KEY)
Addy_INPUT = HOST_URL + STD_URL
try:
for line in urllib2.urlopen(Addy_INPUT):
safe = line
geoQ = safe.find('\"geocodeQualityCode\"',1)
geoCode = safe[(geoQ+22):(geoQ+26)]
if geoCode[0] in okset:
lat = safe.find('\"lat\":', 1)
lng = safe.find('\"lng\":', 1)
lngbound = safe.find('\"mapUrl":', 1)
zipCode = safe.find('\"postalCode\"', 1)
zipbound = safe.find('\"adminArea1\"', 1)
rec["lat"] = float(safe[(lat + 6):
(lng-1)])
rec["long"] = float(safe[(lng+6):
(lngbound-2)])
rec["zip_final"] = safe[(zipCode+14):
(zipbound-2)]
rec["flag"] = 2
print ('ok ')
else:
rec["flag"] = 5
except:
rec["flag"] = 5
rec.store()
del rec
ab.close()
del ab
More information about the Python-list
mailing list