source: trunk/npemap.org.uk/scripts/freethepostcode.org-importer/importer.py @ 33

Last change on this file since 33 was 33, checked in by Nick Burch, 15 years ago

Make a start on the freethepostcode import script

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/python
2#               Importer from FreeThePostcode.org
3#               ---------------------------------
4#
5# Imports FreeThePostcode data into the current schema, removing any
6#  existing FreeThePostcode data.
7#
8# You will need to tweak this script with your database settings for it
9#  to work.
10
11from pyPgSQL import PgSQL
12
13# Database settings
14dbname = "npe_postcodes"
15dbhost = "localhost"
16dbuser = "nick"
17dbpass = ""
18
19
20# Connect to the database
21dbh = None
22if len(dbhost):
23        dbh = PgSQL.connect(database=dbname, host=dbhost, user=dbuser, password=dbpass)
24else:
25        dbh = PgSQL.connect(database=dbname, user=dbuser, password=dbpass)
26
27
28# Check what source value FreeThePostcode data will have
29ftp_source_name = "FreeThePostcode.org Importer"
30ftp_source = None
31
32sql = "SELECT id FROM sources WHERE name = %s"
33sth = dbh.cursor()
34sth.execute(sql, ftp_source_name)
35ids = sth.fetchall()
36if len(ids) == 1:
37        for id in (ids):
38                ftp_source = id.id
39else:
40        print "Unable to find ID for source '%s' - error code %d" % (ftp_source_name, len(ids))
41
42
43# Download the latest list of postcodes
44
45# Prompt before removing all the current ones
46
47# Add the latest list to the database
Note: See TracBrowser for help on using the repository browser.