Changeset 35


Ignore:
Timestamp:
Oct 13, 2006, 11:36:41 AM (13 years ago)
Author:
Nick Burch
Message:

Finish the import script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/scripts/freethepostcode.org-importer/importer.py

    r34 r35  
    4040sth.execute(sql, ftp_source_name)
    4141ids = sth.fetchall()
     42sth.close()
    4243if len(ids) == 1:
    4344        for id in (ids):
     
    103104counts = sth.fetchall()
    104105count = counts[0][0]
     106sth.close()
    105107
    106108print "There are currently %d entries in the database from freethepostcode.org" % count
     
    108110print "Are you sure you wish to remove the old entries, to add new ones?"
    109111confirm = raw_input("")
     112print ""
    110113
    111114if confirm == "y" or confirm == "yes":
     
    121124sth = dbh.cursor()
    122125sth.execute(sql, ftp_source)
     126print "Deleted %d entries" % sth.rowcount
     127sth.close()
     128dbh.commit()
    123129
    124130
    125131# Add the latest list to the database
     132sql = "INSERT INTO postcodes (outward, inward, raw_postcode, easting, northing, source) VALUES (%s, %s, %s, %s, %s, %s)"
     133sth = dbh.cursor()
     134worked = 0
     135for postcode in postcodes:
     136        sth.execute(sql, (postcode["outer"], postcode["inner"], postcode["raw"], postcode["easting"], postcode["northing"], ftp_source))
     137        worked = worked + sth.rowcount
     138print "Added %d entries" % worked
    126139
    127140
     141# All done
     142sth.close()
     143dbh.commit()
     144dbh.close()
Note: See TracChangeset for help on using the changeset viewer.