diff options
author | matthew <matthew> | 2006-10-13 15:37:48 +0000 |
---|---|---|
committer | matthew <matthew> | 2006-10-13 15:37:48 +0000 |
commit | 2f5a698b63f3ea3954d6f2edf3bc41ce37239f0c (patch) | |
tree | 6e1c36f7291357c1c551194dd8082b9b88d25b24 /bin/load-contacts | |
parent | 8d6b393a26ace8c48598cb2cd020ccdc6bacf60b (diff) |
Loading council data into the database; text tweaks.
Diffstat (limited to 'bin/load-contacts')
-rwxr-xr-x | bin/load-contacts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bin/load-contacts b/bin/load-contacts new file mode 100755 index 000000000..bac8497d3 --- /dev/null +++ b/bin/load-contacts @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w + +# canonicalise-csv: +# Convert provided CSV file into one with standard names for MaPit +# +# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: load-contacts,v 1.1 2006-10-13 15:37:48 matthew Exp $ + +use strict; +require 5.8.0; + +# Horrible boilerplate to set up appropriate library paths. +use FindBin; +use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; + +use mySociety::Config; +use mySociety::DBHandle qw(dbh select_all); + +BEGIN { + mySociety::Config::set_file("$FindBin::Bin/../conf/general"); + mySociety::DBHandle::configure( + Name => mySociety::Config::get('BCI_DB_NAME'), + User => mySociety::Config::get('BCI_DB_USER'), + Password => mySociety::Config::get('BCI_DB_PASS'), + Host => mySociety::Config::get('BCI_DB_HOST', undef), + Port => mySociety::Config::get('BCI_DB_PORT', undef) + ); + + if (!dbh()->selectrow_array('select secret from secret for update of secret')) { + local dbh()->{HandleError}; + dbh()->do('insert into secret (secret) values (?)', {}, unpack('h*', mySociety::Util::random_bytes(32))); + } + dbh()->commit(); +} + +open(FP, "$FindBin::Bin/../data/councils_canonical.csv"); +while (<FP>) { + s/\r?\n//g; + my ($id, $email) = split /,/; + dbh()->do("INSERT INTO contacts (area_id, email, editor, whenedited, note) + VALUES (?, ?, 'import', ms_current_timestamp(), 'Initial import')", + {}, $id, $email); +} +dbh()->commit(); +close(FP); |