Changeset 35 for trunk/npemap.org.uk/scripts/freethepostcode.org-importer
- Timestamp:
- Oct 13, 2006, 11:36:41 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/npemap.org.uk/scripts/freethepostcode.org-importer/importer.py
r34 r35 40 40 sth.execute(sql, ftp_source_name) 41 41 ids = sth.fetchall() 42 sth.close() 42 43 if len(ids) == 1: 43 44 for id in (ids): … … 103 104 counts = sth.fetchall() 104 105 count = counts[0][0] 106 sth.close() 105 107 106 108 print "There are currently %d entries in the database from freethepostcode.org" % count … … 108 110 print "Are you sure you wish to remove the old entries, to add new ones?" 109 111 confirm = raw_input("") 112 print "" 110 113 111 114 if confirm == "y" or confirm == "yes": … … 121 124 sth = dbh.cursor() 122 125 sth.execute(sql, ftp_source) 126 print "Deleted %d entries" % sth.rowcount 127 sth.close() 128 dbh.commit() 123 129 124 130 125 131 # Add the latest list to the database 132 sql = "INSERT INTO postcodes (outward, inward, raw_postcode, easting, northing, source) VALUES (%s, %s, %s, %s, %s, %s)" 133 sth = dbh.cursor() 134 worked = 0 135 for postcode in postcodes: 136 sth.execute(sql, (postcode["outer"], postcode["inner"], postcode["raw"], postcode["easting"], postcode["northing"], ftp_source)) 137 worked = worked + sth.rowcount 138 print "Added %d entries" % worked 126 139 127 140 141 # All done 142 sth.close() 143 dbh.commit() 144 dbh.close()
Note: See TracChangeset
for help on using the changeset viewer.