gnue-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUe-dev] zipcode table


From: alex bodnaru
Subject: [GNUe-dev] zipcode table
Date: Thu, 14 Sep 2006 09:17:16 +0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060607 Debian/1.7.12-1.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


hello,

i wish to try gnue, but quite a few examples require a zipcode table,
which has no data to populate it.

after a few googling, i have found a suitable data source, and i provide
a script to make the sql source, as long with the url of provenience.

the script is attached.

best regards and thanks for great gnue,

alex
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Debian - http://enigmail.mozdev.org

iQCVAwUBRQjz7NpwN1sq38njAQJN+QQAxFZsbjVGYu15/igxhpkcRhJb1aNmBpUQ
AEcYJzSTKLhmURxP7JNkNYgNCE2LsgoeFxX0Gh1SeS8R/En8YWO0IyGgqktQzG/r
OkZ7kkSdlX3YjBw8eznAN8ZOmGULK2NrJSeoZxcfsIZXfu6boAmC6wmOFdcOHRt4
lVym/KdizxI=
=XLs/
-----END PGP SIGNATURE-----
# 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 address@hidden
# then just run this script, and the resulting data will populate the
# zipcode table from various gnue examples.
#
# done by alex bodnaru <address@hidden> 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 (zipcode, city, state, longitude, latitude) 
values(%s, %s, %s, %s, %s);" % \
        (str2sql(zipcode), str2sql(city, 1), str2sql(state), 
str2float(longitude), str2float(latitude))

fobj.close()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]