You might also consider reading Green with Addi or Somebody mad at Gap?.
Reminder Perl script
I’m bad with names. I’m bad with dates. I need help putting them together. That’s why several years ago I scratched together some code that emails me (and Jill, although she’s better at remembering) a week prior to and then the day of any event I add to a list.
Anyways, around a year ago I somehow managed to turn the reminder off and it just dawned on me last week that the emails weren’t coming. So yesterday I turned it back on and got to looking at the code — it could use some updating and cleaning up. But for posterity, I’ll post v1 here. And if I haven’t given proper attribution to code I copied from elsewhere, I apologize. It has been so long ago that I wouldn’t know where it came from anyway:
#!/usr/bin/perl -w
use strict;
###########################################
# find current date and time for global use
###########################################
sub timesub {
my $advance = $_[0];
$advance = 0 if !($advance);
my @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
"Sep","Oct","Nov","Dec");
my @days = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
# (time) would be now
my ($sec,$min,$hr,$mday,$mon,$yr,$wday,$yday,$isdst) =
localtime((time+$advance));
# format must be Wed, DD-Mon-YYYY HH:MM:SS GMT
my @timestr = ($mday,($mon+1),$months[$mon]);
return @timestr;
}
###########################################
# main loop
###########################################
reminder("Friends and Family", "dates.txt");
today("Friends and Family", "dates.txt");
###########################################
# send email of reminder dates
###########################################
sub reminder {
my $list_name = $_[0];
my $file_name = $_[1];
my $numofdays = 7; # number of days before the event
# to send the email
$numofdays = $numofdays*24*60*60;
my $header = "$list_name reminder!\n\n";
$header = $header."This is a reminder for you about the following from the $list_name list:\n";
my $footer = "Alright, now go out there and get a card or something!\n";
$footer = $footer."(And, have a great day!)";
my @testday = timesub($numofdays);
open (DATESFILE, $file_name) || exit print "$ENV{HOME}/$file_name:$!";
my @dates = <DATESFILE>;
close(DATESFILE);
my $body;
my $x;
for $x (0 .. $#dates) {
my @line = split(",",$dates[$x]);
my @date = split("/",$line[0]);
$body = $body."$testday[2] $testday[0]: $line[1] - $line[2]\n" if (($date[0]==($testday[1])) and ($date[1]==($testday[0])));
}
if ($body) {
open(MAIL, "| mail -s 'Reminder' me\@example.com");
print MAIL $header.$body.$footer;
close(MAIL);
}
}
###########################################
# send email of today's dates
###########################################
sub today {
my $list_name = $_[0];
my $file_name = $_[1];
my $numofdays = 0; # number of days before the event
# to send the email
$numofdays = $numofdays*24*60*60;
my $header = "$list_name reminder!\n\n";
$header = $header."Today is the day for the following from the $list_name list:\n";
my $footer = "Even though you sent the card already, give them a call!\n";
$footer = $footer."(And, have a great day!)";
my @testday = timesub($numofdays);
open (DATESFILE, $file_name) || exit print "$ENV{HOME}/$file_name:$!";
my @dates = <DATESFILE>;
close(DATESFILE);
my $body;
my $x;
for $x (0 .. $#dates) {
my @line = split(",",$dates[$x]);
my @date = split("/",$line[0]);
$body = $body."$testday[2] $testday[0]: $line[1] - $line[2]\n" if (($date[0]==($testday[1])) and ($date[1]==($testday[0])));
}
if ($body) {
open(MAIL, "| mail -s 'Today' me\@example.com");
print MAIL $header.$body.$footer;
close(MAIL);
}
}
Again, this could be made a lot cleaner, but… it works, get off my back!
The dates.txt file uses the following layout:
5/23, Mom, Birthday
And there you go. (entity-encoded markup via SimpleCode)
written by Kevin in web stuff