Ignore:
Timestamp:
Mar 25, 2007, 6:17:41 PM (15 years ago)
Author:
Nick Burch
Message:

Support IE stuff

File:
1 edited

Legend:

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

    r179 r508  
    1010
    1111from pyPgSQL import PgSQL
    12 from geo_helper import turn_wgs84_into_osgb36, turn_osgb36_into_eastingnorthing
     12from geo_helper import turn_wgs84_into_osgb36, turn_osgb36_into_eastingnorthing, \
     13                                                turn_wgs84_into_osie36, turn_osie36_into_eastingnorthing
    1314import os
    1415
     
    1718dbname = "npemaps"
    1819dbhost = "localhost"
    19 dbuser = "npemap"
    20 dbpass = "npemap"
    21 
    22 
    23 raise Exception("Script needs to be updated as per ticket #39")
     20dbuser = "npemaps"
     21dbpass = ""
    2422
    2523
     
    8785                print "Invalid line '%s'" % line
    8886
    89         # Turn lat+long into easting+northing
    90         osll = turn_wgs84_into_osgb36(parts[0], parts[1], 0)
    91         en = turn_osgb36_into_eastingnorthing(osll[0], osll[1])
    92 
    9387        pc = {}
    94         pc["easting"] = en[0]
    95         pc["northing"] = en[1]
    9688        pc["outer"] = parts[2]
    9789        pc["inner"] = parts[3]
     
    9991        pc["raw_outer"] = parts[2]
    10092        pc["raw_inner"] = parts[3]
     93
     94        pc["easting"] = None
     95        pc["northing"] = None
     96        pc["ie_easting"] = None
     97        pc["ie_northing"] = None
     98
     99        # Turn lat+long into easting+northing
     100        # All NI postcodes are BT
     101        if pc["outer"][0:2] == 'BT':
     102                osll = turn_wgs84_into_osie36(parts[0], parts[1], 0)
     103                en = turn_osie36_into_eastingnorthing(osll[0], osll[1])
     104                pc["ie_easting"] = en[0]
     105                pc["ie_northing"] = en[1]
     106        else:
     107                osll = turn_wgs84_into_osgb36(parts[0], parts[1], 0)
     108                en = turn_osgb36_into_eastingnorthing(osll[0], osll[1])
     109                pc["easting"] = en[0]
     110                pc["northing"] = en[1]
    101111
    102112        postcodes.append(pc)
     
    138148
    139149# Add the latest list to the database
    140 sql = "INSERT INTO postcodes (outward, inward, raw_postcode_outward, raw_postcode_inward, easting, northing, source) VALUES (%s, %s, %s, %s, %s, %s, %s)"
     150sql = "INSERT INTO postcodes (outward, inward, raw_postcode_outward, raw_postcode_inward, easting, northing, ie_easting, ie_northing, source) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
    141151sth = dbh.cursor()
    142152worked = 0
     153
     154# Add the postcodes
    143155for postcode in postcodes:
    144         sth.execute(sql, (postcode["outer"], postcode["inner"], postcode["raw_outer"], postcode["raw_inner"], postcode["easting"], postcode["northing"], ftp_source))
     156        sth.execute(sql, (postcode["outer"], postcode["inner"], postcode["raw_outer"], postcode["raw_inner"], postcode["easting"], postcode["northing"], postcode["ie_easting"], postcode["ie_northing"], ftp_source))
    145157        worked = worked + sth.rowcount
     158
    146159print "Added %d entries" % worked
    147160
Note: See TracChangeset for help on using the changeset viewer.