Regular meeting, 7:30 PM, first Thursday of the month
Route 66 diner, on Central bewteen I-25 and University
Automatic event reminders
Submitted by MrWhat on Wed, 09/12/2007 - 09:44.
I now have a script to email automatic event reminders for drupal.
I'll post the script in the hopes that search engines list it,
and it may be of use to other drupal admins.
Schedule this to run daily:
#!/usr/bin/perl -w
# $Header: /www/www.whovian.us/src/RCS/eventNotify.pl,v 1.2 2007/09/12 21:32:14 $
#
# Send out notification of an upcoming event from a drupal events database
#
##################################################################
# Set these variables as appropriate for your site
$dbName="c9999_drwho";
$dbHost="c9999_drwho.localhost";
$dbUser="c9999_TheMaster";
$dbPswd="myPasswordHere";
$daysAhead = 2; # report events between $daysAhead and $daysAhead+1 days from NOW
$mailTo="member-list\@whovian.us";
$mailFrom="mail-robot\@whovian.us";
# also go to the emailAdditions subroutine to customize message body
##################################################################
use DBI;
$_ = `TZ=America/Denver date`;
print "************ $_";
#$t1 += 1000000; # make sure there is an event for debug
##### get any events in the indicated time frame
$db = DBI->connect("DBI:mysql:database=$dbName:host=$dbHost",$dbUser,$dbPswd);
$q = "select nid,event_start from event where (event_start > $t0) and (event_start < $t1)";
print "$q\n";
#$q = "select nid,event_start from event"; print "$q\n";
$cmd = $db->prepare($q);
$cmd->execute;
$i=0;
while( ($id,$startSSE) = $cmd->fetchrow() ) {
$nid[$i] = $id;
$sse[$i] = $startSSE;
print "$i) nid=$id sse=$startSSE\n";
$i++;
}
if ($i <= 0){
print "No events found\n";
exit(0);
}
$cmd->finish;
##### get event body
$q = "select body from node_revisions where nid=" . $nid[0];
print "$q\n";
$cmd = $db->prepare($q);
$cmd->execute;
$body = $cmd->fetchrow();
$cmd->finish;
print "$body\n";
$db->disconnect;
##### Convert event SSE to typical date and time
$d = "TZ=America/Denver date -r " . $sse[0] . " \'+%a %b %d %l:%M %p\'";
$_ = `$d`;
$date=substr($_,0,10);
$tod =substr($_,11,8);
# add headers and footers (and maybe other stuff) to e-mail body
$body = &emailAdditions($date,$tod,$body);
&sendMail($mailFrom, $mailTo,
"Event Reminder-$date",$body);
#===============================================================
sub getTimeSpan{
$_ = `date +%s`;
s/\n//; s/\r//; # for some reason, chomp destroys value
local $t = $_;
local $t0 = $t + ($daysAhead * 86400);
local $t1 = $t0 + 86400;
return($t,$t0,$t1);
}
sub sendMail {
local ($from, $to, $subject, $body) = @_;
$_ = "|/usr/sbin/sendmail $to"; print "$_\n";
open(F,$_);
print F "From: $from\nTo: $to\nSubject: $subject\n\n$body\n";
close(F);
}
################# Customize this for your group
sub emailAdditions {
local ($date,$tod,$body) = @_;
# make sure relative URL's are made global
$_=$body; s/"\?q=/"http:\/\/whovian.us\/drupal\/?q=/g;
$body = "ABQ Dr. Who Event, $date at $tod :
------------------------------------------------\n\n" . $_;
$body .= "\n\n--
Automatic Mailing from ABQ Whovians
For full event listing, see:
http://whovian.us/drupal/?q=event\n";
print "$body\n";
return($body);
}
__END__
»
- MrWhat's blog
- Login or register to post comments
