From 07dc1bf5158b8a527e76134e6245f8cfa8181dc1 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Fri, 9 Dec 2016 13:48:24 -0800 Subject: [PATCH] add-postal address script. --- scripts/add-postal-address.plx | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 scripts/add-postal-address.plx diff --git a/scripts/add-postal-address.plx b/scripts/add-postal-address.plx new file mode 100644 index 0000000..1b904cf --- /dev/null +++ b/scripts/add-postal-address.plx @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DBI; +use Encode qw(encode decode); +use Supporters; + +if (@ARGV != 1 and @ARGV !=2) { + print STDERR "usage: $0 \n"; + exit 1; +} + +my($SUPPORTERS_SQLITE_DB_FILE, $VERBOSE) = @ARGV; +$VERBOSE = 0 if not defined $VERBOSE; + +my $dbh = DBI->connect("dbi:SQLite:dbname=$SUPPORTERS_SQLITE_DB_FILE", "", "", + { RaiseError => 1, sqlite_unicode => 1 }) + or die $DBI::errstr; + +print "Supporter Id: "; +my $supporterId = ; +chomp $supporterId; + +print "postal Address (. to end):\n"; +my $postal = ""; +while (my $line = ) { + last if $line =~ /^\s*\.\s*$/; + $postal .= $line; +} + +print "Postal Address Type: "; +my $postalType = ; +chomp $postalType; + +print "Preferred (0 or 1): "; +my $preferred = ; +chomp $preferred; + +my $sp = new Supporters($dbh, [ "none" ]); + +$sp->addPostalAddress($supporterId, $postal, $postalType); + +print "Preferred postal address was: ", $sp->getPreferredPostalAddress($supporterId), "\n"; +if ($preferred) { + $sp->setPreferredPostalAddress($supporterId, $postal); + print "Preferred postal address is now: ", $sp->getPreferredPostalAddress($supporterId), "\n"; +}