Changeset 127


Ignore:
Timestamp:
Oct 22, 2006, 12:16:16 AM (13 years ago)
Author:
Nick Burch
Message:

Update for new schema. Don't require a prompt about the change if it's a sensible, small one

File:
1 edited

Legend:

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

    r83 r127  
    9494        pc["inner"] = parts[3]
    9595        pc["raw"] = "%s %s" % (parts[2],parts[3])
     96        pc["raw_outer"] = parts[2]
     97        pc["raw_inner"] = parts[3]
    9698
    9799        postcodes.append(pc)
     
    108110print "There are currently %d entries in the database from freethepostcode.org" % count
    109111print "The new import contains %d entries" % len(postcodes)
    110 print "Are you sure you wish to remove the old entries, to add new ones?"
    111 confirm = raw_input("")
    112 print ""
    113112
    114 if confirm == "y" or confirm == "yes":
    115         # Good, go ahead
    116         pass
    117 else:
     113# Only prompt if it's a big difference
     114if count == 0 or len(postcodes) == 0 or len(postcodes) < count or (len(postcodes)-count) > 50:
     115        print "Are you sure you wish to remove the old entries, to add new ones?"
     116        confirm = raw_input("")
    118117        print ""
    119         raise Exception("Aborting import")
     118
     119        if confirm == "y" or confirm == "yes":
     120                # Good, go ahead
     121                pass
     122        else:
     123                print ""
     124                raise Exception("Aborting import")
    120125
    121126
     
    130135
    131136# 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)"
     137sql = "INSERT INTO postcodes (outward, inward, raw_postcode_outward, raw_postcode_inward, easting, northing, source) VALUES (%s, %s, %s, %s, %s, %s, %s)"
    133138sth = dbh.cursor()
    134139worked = 0
    135140for postcode in postcodes:
    136         sth.execute(sql, (postcode["outer"], postcode["inner"], postcode["raw"], postcode["easting"], postcode["northing"], ftp_source))
     141        sth.execute(sql, (postcode["outer"], postcode["inner"], postcode["raw_outer"], postcode["raw_inner"], postcode["easting"], postcode["northing"], ftp_source))
    137142        worked = worked + sth.rowcount
    138143print "Added %d entries" % worked
Note: See TracChangeset for help on using the changeset viewer.