2016-01-02 18:33:35 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use autodie qw(open close);
|
|
|
|
use DBI;
|
|
|
|
use Encode qw(encode decode);
|
|
|
|
|
2016-01-02 18:33:57 +00:00
|
|
|
use Supporters;
|
|
|
|
|
2016-01-02 18:33:35 +00:00
|
|
|
my $LEDGER_CMD = "/usr/local/bin/ledger";
|
|
|
|
|
2017-08-01 17:17:19 +00:00
|
|
|
if (@ARGV != 5 and @ARGV != 6) {
|
|
|
|
print STDERR "usage: $0 <SUPPORTERS_SQLITE_DB_FILE> <T_SHIRT_TYPE> <WHO> <HOW> <SUPPORTER_CHECKLIST_TEX_FILE> <VERBOSITY_LEVEL>\n";
|
2016-01-02 18:33:35 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my($SUPPORTERS_SQLITE_DB_FILE, $WHO, $HOW, $TEX_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;
|
|
|
|
|
|
|
|
my $sp = new Supporters($dbh, [ "none" ]);
|
|
|
|
|
|
|
|
my %idsSent;
|
|
|
|
open(TEX_FILE, "<", $TEX_FILE);
|
|
|
|
|
|
|
|
while (my $line = <TEX_FILE>) {
|
|
|
|
if ($line =~ /Box.*\&\s*(\d+)\s*\&\s*(\S+)\s*\&\s*(\S+)\s*\&/) {
|
|
|
|
my($id, $ledgerEntityId, $size) = ($1, $2, $3);
|
|
|
|
die "id $id, and/or size $size not defined" unless defined $id and defined $size;
|
2017-01-02 19:57:42 +00:00
|
|
|
$idsSent{$id}{$size} = 0 if not defined $idsSent{$id}{$size};
|
|
|
|
$idsSent{$id}{$size}++;
|
2016-01-02 18:33:35 +00:00
|
|
|
} else {
|
2016-01-02 18:47:09 +00:00
|
|
|
print STDERR "skipping line $line" if ($VERBOSE >= 2);
|
2016-01-02 18:33:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close TEX_FILE;
|
|
|
|
|
|
|
|
foreach my $id (sort keys %idsSent) {
|
2016-12-08 23:08:53 +00:00
|
|
|
my @requestTypes = $sp->getRequestType();
|
2017-01-02 19:57:42 +00:00
|
|
|
my $sizesSent;
|
2017-01-10 19:36:50 +00:00
|
|
|
my $foundRequestCount = 0;
|
2016-12-08 23:08:53 +00:00
|
|
|
foreach my $type (@requestTypes) {
|
2017-08-01 17:17:19 +00:00
|
|
|
next unless ($type =~ /shirt/ and $type =~ /$T_SHIRT_TYPE/);
|
2017-01-10 19:36:50 +00:00
|
|
|
my $request = $sp->getRequest({ donorId => $id, requestType => $type,
|
2016-12-08 23:08:53 +00:00
|
|
|
ignoreHeldRequests => 1, ignoreFulfilledRequests => 1 });
|
2017-01-10 19:36:50 +00:00
|
|
|
if (defined $request and defined $request->{requestId} and defined $request->{requestType}) {
|
|
|
|
$foundRequestCount++;
|
2017-01-02 19:57:42 +00:00
|
|
|
my $size = $request->{requestConfiguration};
|
|
|
|
if (not defined $idsSent{$id}{$size} and $idsSent{$id}{$size}-- > 0) {
|
2016-01-02 18:33:35 +00:00
|
|
|
my $out = "WARNING: not fufilling $id request for $request->{requstConfiguration} because we sent wrong size of $idsSent{$id}!\n";
|
|
|
|
print $out;
|
|
|
|
print STDERR $out;
|
|
|
|
$request = undef;
|
2017-01-02 19:57:42 +00:00
|
|
|
} else {
|
2017-01-10 19:36:50 +00:00
|
|
|
$sp->fulfillRequest({ donorId => $id, requestType => $request->{requestType},
|
|
|
|
who => $WHO, how => $HOW});
|
2017-01-02 19:57:42 +00:00
|
|
|
if (defined $sizesSent) {
|
|
|
|
$sizesSent .= ", $size";
|
|
|
|
} else {
|
|
|
|
$sizesSent .= "$size";
|
|
|
|
}
|
2016-01-02 18:33:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 19:36:50 +00:00
|
|
|
unless ($foundRequestCount > 0) {
|
2017-01-02 19:57:42 +00:00
|
|
|
my $out = "WARNING: We seem to have sent $id a t-shirt that $id didn't request! Ignoring that and contuining...\n";
|
2016-01-02 18:33:35 +00:00
|
|
|
print $out;
|
|
|
|
print STDERR $out;
|
|
|
|
next;
|
|
|
|
}
|
2017-01-10 19:36:50 +00:00
|
|
|
next unless $sp->emailOk($id);
|
2017-08-01 16:19:45 +00:00
|
|
|
my @emails;
|
|
|
|
my $preferredEmail = $sp->getPreferredEmailAddress($id);
|
|
|
|
if (defined $preferredEmail) {
|
|
|
|
push(@emails, $preferredEmail);
|
|
|
|
} else {
|
|
|
|
my(%emailData) = $sp->getEmailAddresses($id);
|
|
|
|
(@emails) = keys %emailData;
|
|
|
|
}
|
|
|
|
my $fullEmailLine = "";
|
|
|
|
my $emailTo = join(' ', @emails);
|
|
|
|
my $displayName = $sp->getDisplayName($id);
|
|
|
|
print "Email to:$emailTo, displayName $displayName\n";
|
|
|
|
foreach my $email (@emails) {
|
|
|
|
$fullEmailLine .= ", " if ($fullEmailLine ne "");
|
|
|
|
my $line = "";
|
|
|
|
if (defined $displayName) {
|
|
|
|
$line .= "\"$displayName\" ";
|
|
|
|
}
|
|
|
|
$line .= "<$email>";
|
|
|
|
$fullEmailLine .= Encode::encode("MIME-Header", $line);
|
2016-01-02 18:33:35 +00:00
|
|
|
}
|
2017-08-01 16:19:45 +00:00
|
|
|
|
2016-01-02 18:33:35 +00:00
|
|
|
my $fromAddress = 'info@sfconservancy.org';
|
2016-03-01 01:58:37 +00:00
|
|
|
my $pingNoGet = "";
|
|
|
|
$pingNoGet = "\nPlease ping us if you do not receive your t-shirt within two weeks in the\nUSA, or three weeks outside of the USA.\n\n"
|
|
|
|
if ($HOW =~ /post/);
|
|
|
|
|
2016-01-02 18:47:29 +00:00
|
|
|
open(SENDMAIL, "|/usr/lib/sendmail -f \"$fromAddress\" -oi -oem -- $emailTo $fromAddress") or
|
2016-01-02 18:33:35 +00:00
|
|
|
die "unable to run sendmail: $!";
|
|
|
|
print SENDMAIL <<DATA;
|
2017-08-01 16:19:45 +00:00
|
|
|
To: $fullEmailLine
|
2016-01-02 18:33:35 +00:00
|
|
|
From: "Software Freedom Conservancy" <$fromAddress>
|
2017-01-02 19:57:42 +00:00
|
|
|
Subject: $sizesSent Conservancy T-Shirt was $HOW
|
2016-01-02 18:33:35 +00:00
|
|
|
|
2017-01-02 19:57:42 +00:00
|
|
|
According to our records, the t-shirt of size $sizesSent that you
|
2016-03-01 01:58:37 +00:00
|
|
|
requested as a Conservancy Supporter was $HOW.
|
|
|
|
$pingNoGet
|
2016-01-02 18:33:35 +00:00
|
|
|
|
2017-01-02 19:57:42 +00:00
|
|
|
Thank you again so much for supporting Conservancy.
|
2016-10-20 18:18:32 +00:00
|
|
|
|
|
|
|
We'd really appreciate if you'd post pictures of the shirt on social media
|
|
|
|
and encourage others to sign up as a Conservancy supporter at
|
2017-01-02 19:57:42 +00:00
|
|
|
https://sfconservancy.org/supporter/ . As you can see on that page, we are
|
|
|
|
in the midst of our annual fundraising drive and seeking to reach a match
|
2017-08-01 16:19:57 +00:00
|
|
|
donation. There's a unique opportunity remaining for just two more days for
|
|
|
|
us to make a match donation.
|
|
|
|
|
|
|
|
So, encouraging others to sign up right now will make a huge difference!
|
|
|
|
|
|
|
|
Thank you again for your support of Conservancy.
|
2016-01-02 18:33:35 +00:00
|
|
|
|
|
|
|
Sincerely,
|
|
|
|
--
|
2016-01-07 06:22:44 +00:00
|
|
|
Karen M. Sandler, Executive Director, Software Freedom Conservancy
|
|
|
|
and
|
|
|
|
Bradley M. Kuhn, Distinguished Technologist, Software Freedom Conservancy
|
2016-01-02 18:33:35 +00:00
|
|
|
DATA
|
|
|
|
close SENDMAIL;
|
|
|
|
die "Unable to send email to $id: $!" unless $? == 0;
|
2016-01-02 18:47:22 +00:00
|
|
|
|
2017-01-02 19:57:42 +00:00
|
|
|
print STDERR "Emailed $emailTo for $id sending of $sizesSent size t-shirt and marked it fulfilled in database\n" if ($VERBOSE);
|
2016-01-02 18:33:35 +00:00
|
|
|
}
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# compile-command: "perl -c send-t-shirts.plx"
|
|
|
|
# End:
|
|
|
|
|