Author: reinhard Date: 2006-09-26 13:16:31 -0500 (Tue, 26 Sep 2006) New Revision: 8702
Added: trunk/gnue-forms/samples/zipcode/zipparse.py Log: Added script contributed by Alex Bodnaru to read ZIP data from a file. Added: trunk/gnue-forms/samples/zipcode/zipparse.py =================================================================== --- trunk/gnue-forms/samples/zipcode/zipparse.py 2006-09-26 14:00:17 UTC (rev 8701) +++ trunk/gnue-forms/samples/zipcode/zipparse.py 2006-09-26 18:16:31 UTC (rev 8702) @@ -0,0 +1,31 @@ +# utility to create the sql needed for populating the zipcode table. +# you should first download and unpack the text file from +# http://www.cfdynamics.com/zipbase/, courtesy to [EMAIL PROTECTED] +# then just run this script, and the resulting data will populate the +# zipcode table from various gnue examples. +# +# done by alex bodnaru <[EMAIL PROTECTED]> for the gnue project, but +# may be used for any purpose, without holding the author responsible +# for any bad results may happen (but i won't wish that will). + +import csv, string + +def str2sql(string, capitalize=0): + if capitalize: + string = " ".join([word.capitalize() for word in string.split()]) + return "'" + string.replace("'", "''") + "'" + +def str2float(string): + if string: + return str(float(string)) + else: return 'NULL' + +fobj = open("ZIP_CODES.txt") +reader = csv.reader(fobj) + +#"00501","+40.922326","-072.637078","HOLTSVILLE","NY","SUFFOLK","UNIQUE" +for zipcode, latitude, longitude, city, state, county, zip_class in reader: + print "insert into zipcode (zip, city, state, longitude, latitude) values(%s, %s, %s, %s, %s);" % \ + (str2sql(zipcode), str2sql(city, 1), str2sql(state), str2float(longitude), str2float(latitude)) + +fobj.close() _______________________________________________ commit-gnue mailing list [email protected] http://lists.gnu.org/mailman/listinfo/commit-gnue
