Version as used for the postcard.

This commit is contained in:
Bradley M. Kuhn 2022-06-21 10:15:34 -07:00
parent 284d5889b1
commit 10e68afa95

View file

@ -21,7 +21,6 @@ require 'bean-query-daemon-lib.pl';
my $TOTAL_GROUPS = 2; my $TOTAL_GROUPS = 2;
BeancountQueryInitialize();
binmode STDOUT, ":utf8"; binmode STDOUT, ":utf8";
my $encoder = Email::MIME::RFC2047::Encoder->new(); my $encoder = Email::MIME::RFC2047::Encoder->new();
@ -36,29 +35,40 @@ my $NINE_MONTHS_AGO = UnixDate(ParseDate("9 months ago"), '%Y-%m-%d');
my $FIFTEEN_MONTHS_AGO = UnixDate(ParseDate("15 months ago"), '%Y-%m-%d'); my $FIFTEEN_MONTHS_AGO = UnixDate(ParseDate("15 months ago"), '%Y-%m-%d');
my $NINETEEN_MONTHS_AGO = UnixDate(ParseDate("19 months ago"), '%Y-%m-%d'); my $NINETEEN_MONTHS_AGO = UnixDate(ParseDate("19 months ago"), '%Y-%m-%d');
my $THREE_TWENTY_DAYS_AGO = UnixDate(ParseDate("320 days ago"), '%Y-%m-%d'); my $THREE_TWENTY_DAYS_AGO = UnixDate(ParseDate("320 days ago"), '%Y-%m-%d');
my $THREE_MONTHS_AGO = UnixDate(ParseDate("3 months ago"), '%Y-%m-%d');
my $FY_2019_FUNDRAISER_START = UnixDate(ParseDate("2019-11-26 08:00"), '%Y-%m-%d'); my $FY_2019_FUNDRAISER_START = UnixDate(ParseDate("2019-11-26 08:00"), '%Y-%m-%d');
my $NOV_19_2018 = UnixDate(ParseDate("2018-11-19 08:00"), '%Y-%m-%d'); my $NOV_19_2018 = UnixDate(ParseDate("2018-11-19 08:00"), '%Y-%m-%d');
my $NOV_20_2019 = UnixDate(ParseDate("2018-11-20 08:00"), '%Y-%m-%d'); my $NOV_20_2019 = UnixDate(ParseDate("2018-11-20 08:00"), '%Y-%m-%d');
my $NOV_24_2020 = UnixDate(ParseDate("2020-11-24 00:00"), '%Y-%m-%d'); my $NOV_24_2020 = UnixDate(ParseDate("2020-11-24 00:00"), '%Y-%m-%d');
my $DEC_8_2020 = UnixDate(ParseDate("2020-12-08 00:00"), '%Y-%m-%d');
my $DEC_22_2020 = UnixDate(ParseDate("2020-12-22 00:00"), '%Y-%m-%d');
my $NOV_20_2020 = UnixDate(ParseDate("2020-11-20 00:00"), '%Y-%m-%d'); my $NOV_20_2020 = UnixDate(ParseDate("2020-11-20 00:00"), '%Y-%m-%d');
my $JAN_20_2019 = UnixDate(ParseDate("2019-01-20 08:00"), '%Y-%m-%d'); my $JAN_20_2019 = UnixDate(ParseDate("2019-01-20 08:00"), '%Y-%m-%d');
my $JAN_15_2020 = UnixDate(ParseDate("2020-01-15 08:00"), '%Y-%m-%d'); my $JAN_15_2020 = UnixDate(ParseDate("2020-01-15 08:00"), '%Y-%m-%d');
my $JAN_31_2021 = UnixDate(ParseDate("2021-01-31 20:00"), '%Y-%m-%d');
my $JAN_15_2019 = UnixDate(ParseDate("2019-01-15 08:00"), '%Y-%m-%d'); my $JAN_15_2019 = UnixDate(ParseDate("2019-01-15 08:00"), '%Y-%m-%d');
my $JAN_1_2020 = UnixDate(ParseDate("2020-01-01 08:00"), '%Y-%m-%d'); my $JAN_1_2020 = UnixDate(ParseDate("2020-01-01 08:00"), '%Y-%m-%d');
my $JAN_1_2021 = UnixDate(ParseDate("2021-01-01 08:00"), '%Y-%m-%d');
my $JAN_1_2022 = UnixDate(ParseDate("2022-01-01 08:00"), '%Y-%m-%d');
my $JUN_1_2017 = UnixDate(ParseDate("2017-06-01 08:00"), '%Y-%m-%d');
my $START_OF_CY_2020_FUNDRAISER = UnixDate(ParseDate("2020-11-24 00:00"), '%Y-%m-%d'); my $START_OF_CY_2020_FUNDRAISER = UnixDate(ParseDate("2020-11-24 00:00"), '%Y-%m-%d');
my $MAR_1_2020 = UnixDate(ParseDate("2020-03-01 08:00"), '%Y-%m-%d'); my $MAR_1_2020 = UnixDate(ParseDate("2020-03-01 08:00"), '%Y-%m-%d');
my $MAR_1_2019 = UnixDate(ParseDate("2019-03-01 08:00"), '%Y-%m-%d'); my $MAR_1_2019 = UnixDate(ParseDate("2019-03-01 08:00"), '%Y-%m-%d');
my $OCT_1_2020 = UnixDate(ParseDate("2020-10-01 08:00"), '%Y-%m-%d'); my $OCT_1_2020 = UnixDate(ParseDate("2020-10-01 08:00"), '%Y-%m-%d');
my $END_LAST_YEAR = '2017-12-31'; my $END_LAST_YEAR = '2020-12-31';
my $OCT_19_2021 = UnixDate(ParseDate("2021-10-19 08:00"), '%Y-%m-%d');
my $NOV_2_2021 = UnixDate(ParseDate("2021-11-02 08:00"), '%Y-%m-%d');
my $NOV_21_2021 = UnixDate(ParseDate("2021-11-21 08:00"), '%Y-%m-%d');
if (@ARGV < 6) { if (@ARGV < 6) {
print STDERR "usage: $0 <SUPPORTERS_SQLITE_DB_FILE> <FROM_ADDRESS> <EMAIL_TEMPLATE_SUFFIX> <BAD_ADDRESS_LIST_FILE> <MONTHLY_SEARCH_REGEX> <ANNUAL_SEARCH_REGEX> <VERBOSE>\n"; print STDERR "usage: $0 <SUPPORTERS_SQLITE_DB_FILE> <FROM_ADDRESS> <EMAIL_TEMPLATE_SUFFIX> <BAD_ADDRESS_LIST_FILE> <MONTHLY_SEARCH_REGEX> <ANNUAL_SEARCH_REGEX> <GLUE> <VERBOSE>\n";
exit 1; exit 1;
} }
my($SUPPORTERS_SQLITE_DB_FILE, $FROM_ADDDRESS, $EMAIL_TEMPLATE_SUFFIX, $BAD_ADDRESS_LIST_FILE, $MONTHLY_SEARCH_REGEX, $ANNUAL_SEARCH_REGEX, $VERBOSE) = @ARGV; my($SUPPORTERS_SQLITE_DB_FILE, $FROM_ADDDRESS, $EMAIL_TEMPLATE_SUFFIX, $BAD_ADDRESS_LIST_FILE, $MONTHLY_SEARCH_REGEX, $ANNUAL_SEARCH_REGEX, $VERBOSE) = @ARGV;
$VERBOSE = 0 if not defined $VERBOSE; $VERBOSE = 0 if not defined $VERBOSE;
BeancountQueryInitialize("BeAn");
my $dbh = DBI->connect("dbi:SQLite:dbname=$SUPPORTERS_SQLITE_DB_FILE", "", "", my $dbh = DBI->connect("dbi:SQLite:dbname=$SUPPORTERS_SQLITE_DB_FILE", "", "",
{ RaiseError => 1, sqlite_unicode => 1 }) { RaiseError => 1, sqlite_unicode => 1 })
or die $DBI::errstr; or die $DBI::errstr;
@ -108,7 +118,7 @@ my %groupCounts;
for my $ii (0 .. $TOTAL_GROUPS) { $groupCounts{$ii} = 0; } for my $ii (0 .. $TOTAL_GROUPS) { $groupCounts{$ii} = 0; }
my(@supporterIds) = $sp->findDonor({}); my(@supporterIds) = $sp->findDonor({});
open(my $idsInUSAFH, "<", catfile($ENV{CONSERVANCY_REPOSITORY}, 'Fundraising/Supporters/2020-12_Postcard', open(my $idsInUSAFH, "<", catfile($ENV{CONSERVANCY_REPOSITORY}, 'Fundraising/Supporters/2021-12_Postcard',
'donor-ids-in-usa.txt')); 'donor-ids-in-usa.txt'));
my %idsKnownToBeInUSA; my %idsKnownToBeInUSA;
while (my $idInUSA = <$idsInUSAFH>) { while (my $idInUSA = <$idsInUSAFH>) {
@ -137,18 +147,29 @@ foreach my $id (sort { $a <=> $b } @supporterIds) {
if (not $likelyUSA) { if (not $likelyUSA) {
foreach $postalAddress (@postalAddresses) { foreach $postalAddress (@postalAddresses) {
$likelyUSA = 1 $likelyUSA = 1
if ($postalAddress =~ /United\s*States|USA|,\s*\S+\s+\d{5,5}(\s+|$)|,\s*\S+\s+\d{5,5}\-\d{4,4}(\s+|$)/mi if (defined $postalAddress and
and (not $postalAddress =~ /Saudi\s*Arabia|France|Sweden|Uruguay|Bulgaria|Indonesia|Switzerland|Spain|Brasil|Brazil|Estonia|Germany|Bosnia|Herzegovina|Italy|Czech|Finland|Korea|Ireland/im)) $postalAddress =~ /United\s*States|USA|,\s*\S+\s+\d{5,5}(\s+|$)|,\s*\S+\s+\d{5,5}\-\d{4,4}(\s+|$)/mi
and (not $postalAddress =~ /Saudi\s*Arabia|France|Sweden|Uruguay|Bulgaria|Indonesia|Switzerland|Spain|Brasil|Brazil|Estonia|Germany|Bosnia|Herzegovina|Italy|Czech|Finland|Korea|Ireland/im));
} }
} }
my $group = 0; my $group = 0;
my $specialContact = "";
if (not $sp->emailOk($id)) {
my $req = $sp->getRequest({donorId => $id, requestType => 'contact-setting'});
if (defined $req and defined $req->{requestConfiguration} and
$req->{requestConfiguration} eq 'only-one-annual-renewal-notice') {
$specialContact = 'only-one-annual-renewal-notice: ';
} else {
print "NOT-SENT: SUPPORTER $id: has requested no email contact\n";
$groupCounts{$group}++;
next;
}
}
if (not $sp->emailOk($id)) { if (not $sp->emailOk($id)) {
print "NOT-SENT: SUPPORTER $id: supporter is unsubscribed from mass emails.\n"; print "NOT-SENT: SUPPORTER $id: supporter is unsubscribed from mass emails.\n";
$groupCounts{0}++; $groupCounts{0}++;
next; next;
} }
my $specialContact = "";
# Set up emails first in case we want to use it in the group tests below # Set up emails first in case we want to use it in the group tests below
my %emails; my %emails;
my $email = $sp->getPreferredEmailAddress($id); my $email = $sp->getPreferredEmailAddress($id);
@ -172,6 +193,13 @@ foreach my $id (sort { $a <=> $b } @supporterIds) {
} }
my(@emails) = keys(%emails); my(@emails) = keys(%emails);
if ($lastGaveDate ge $NOV_20_2020 and $lastGaveDate le $JAN_31_2021) {
$group = 2;
} elsif ($lastGaveDate ge $NOV_21_2021) {
$group = 1;
} elsif ($lastGaveDate lt $NOV_21_2021 or ($lastGaveDate gt $JAN_31_2021 and $lastGaveDate lt $NOV_20_2020)) {
$groupCounts{-1} = 0 unless defined $groupCounts{-1};
$groupCounts{-1}++;
# if (not $sp->emailOk($id)) { # if (not $sp->emailOk($id)) {
# my $req = $sp->getRequest({donorId => $id, requestType => 'contact-setting'}); # my $req = $sp->getRequest({donorId => $id, requestType => 'contact-setting'});
# if (defined $req and defined $req->{requestConfiguration} and # if (defined $req and defined $req->{requestConfiguration} and
@ -185,14 +213,14 @@ foreach my $id (sort { $a <=> $b } @supporterIds) {
# } # }
# Use above commented out section instead of next line when you want to send an annual renewal notice and not a mass mailing # Use above commented out section instead of next line when you want to send an annual renewal notice and not a mass mailing
$lastGaveDate = '0001-01-01' if not defined $lastGaveDate; # $lastGaveDate = '0001-01-01' if not defined $lastGaveDate;
$donorType = 'annual' if not defined $donorType or $donorType eq ""; # $donorType = 'annual' if not defined $donorType or $donorType eq "";
if ($lastGaveDate le $NINETEEN_MONTHS_AGO) { # if ($lastGaveDate le $NINETEEN_MONTHS_AGO) {
$group = 1; # $group = 1;
} elsif ($lastGaveDate gt $NINETEEN_MONTHS_AGO and $lastGaveDate lt $NOV_24_2020) { # } elsif ($lastGaveDate gt $NINETEEN_MONTHS_AGO and $lastGaveDate lt $NOV_24_2020) {
$group = 2; # $group = 2;
} elsif ($lastGaveDate ge $NOV_24_2020) { # } elsif ($lastGaveDate ge $NOV_24_2020) {
$group = 0; # $group = 0;
# if ($lastGaveDate ge $NOV_19_2018 and $lastGaveDate le $JAN_20_2019) { # if ($lastGaveDate ge $NOV_19_2018 and $lastGaveDate le $JAN_20_2019) {
# $group = 1; # $group = 1;
# } elsif ($lastGaveDate lt $NOV_19_2018) { # } elsif ($lastGaveDate lt $NOV_19_2018) {