#!/usr/bin/perl # this script runs through the various bible verses daily # (incrementing number.txt) and mails em out. require '/usr/home/fso/libs/fso-g-lib.pl'; require '/usr/home/em/libs/em-defs.pl'; require '/usr/home/em/libs/em-g-lib.pl'; use Date::Manip; use File::Copy; $lyris::config_filename = "/opt/lyris/cgi/lyris.plc"; my $rc = &lyris::init; $| = 1; $DEBUG = 1; # TOP_DIR hack $TOP_DIR = "${TOP_DIR}/bv"; $N_DATE = &UnixDate('today', '%m-%d-%Y'); # MMDDYY $AD_DATE = "ad.html." . &UnixDate('today', '%m%d%y'); # %Y_%m_%d_%H:%M:%S $timestamp = &UnixDate('today', '%Y%m%d%H%M%S'); $BIBLE_TYPE{ASV} = "American Standard Version"; $BIBLE_TYPE{KJV} = "King James Version"; $BIBLE_TYPE{NAS} = "New American Standard"; $BIBLE_TYPE{NIV} = "New International Version"; $BIBLE_TYPE{NKJ} = "New King James Version"; $CONTENT = "${TOP_DIR}/bibleverses/verses/combined"; $LIST = "bibleverses"; $CONTENT = "$TOP_DIR/bibleverses/verses/combined"; $REPLYTO = "bv-html-reply\@DailyInbox.com"; $OURMAIL = "bv-html\@DailyInbox.com"; $BASE = "$SYSURL/daily"; $LAST_MAILED_CONTENT = "last.mailed.bv.html"; # name of file where last send is kept $CHECK_FOR_DUPS = 1; # set it to prevent a dup submission from going through $SUBJECT = "DailyInbox.com - Bible Verses - $N_DATE"; $NUMBER_FILE = "$TOP_DIR/$LIST/verses/kjv/number.txt"; #$LIST = "bibleverses"; #$CONTENT = "$TOP_DIR/$LIST/verses/combined"; open(LOG, ">>/opt/bv_send.log"); $date = `/usr/bin/date`; chomp($date); print LOG "\n-----------------------------\nStarting [bv_html] $LIST send run - $date\n"; if ( ! -f $NUMBER_FILE ) { print LOG "Creating number.txt file for the first time.\n"; open(OUT, ">$NUMBER_FILE") or failure("EM - $LIST - couldn't open outfile number.txt"); print OUT "1\n"; close(OUT); } open(IN, "<$NUMBER_FILE") or failure("EM - $LIST - couldn't open infile number.txt"); $CURRENT = ; chomp($CURRENT); if ( $CURRENT !~ /\d+/ ) { # chk to make sure we got a digit or a few failure("EM - $LIST - didn't get a valid number from number.txt"); } close(IN); print LOG "ID: $CURRENT\n"; $NEW = $CURRENT; open(IN, "<$CONTENT/$NEW") or failure("EM - $LIST - couldn't open content file [$CONTENT/$NEW]"); $LINE1 = ; @LINES = ; print LOG "Successfully retrieved content for send.\n"; $SUBJECT = "DailyInbox.com - Bible Verses - $LINE1 - $N_DATE"; # $page = "

Daily Bible Verse

"; $page .= "

\n"; $page .= ""; foreach (@LINES) { if ( /FRONTLET.(.*)/ ) { #$page .= "\n"; #$page .= "\n"; $first_part = $BIBLE_TYPE{$1}; } else { #$page .= "\n"; $page .= "\n"; } } $page .= "
Today's selection is $LINE1

$BIBLE_TYPE{$1}
$_
$first_part
$_
\n"; open (DAILY, "> $TOP_DIR/daily.html"); print DAILY "$page \n"; close DAILY; my $ad_text = ""; # if the ad file exists, insert it... if ( -f "$TOP_DIR/bibleverses/ads/$AD_DATE" ) { print LOG "Ad file [$AD_DATE] exists...processing.\n"; open (STOP, "< $TOP_DIR/bibleverses/ads/$AD_DATE"); my @slurp = ; foreach $what (@slurp) { $ad_text .= $what; } print LOG "-> Copying [$AD_DATE] to [ad.html]\n"; copy ("$TOP_DIR/bibleverses/ads/$AD_DATE", "$TOP_DIR/bibleverses/ads/ad.html"); } else { # else, just but a byte in the file (it must exist) print LOG "Creating empty [ad.html]\n"; open (STOP, "> $TOP_DIR/bibleverses/ads/ad.html"); print STOP ""; close STOP; } # jim's version of SSI... open (INDEX, "< $TOP_DIR/index2.shtml"); my @file = ; foreach $line (@file) { if ( $line =~ /daily.html/ ) { $bbody .= "$page"; } if ( $line =~ /simpletop2.html/ ) { open (STOP, "< $TOP_DIR/simpletop2.html"); my @slurp = ; foreach $what (@slurp) { if ( $what =~ /timestamp/ ) { $what =~ s/timestamp/$timestamp/g; } $bbody .= $what; } } if ( $line =~ /ad.html/ ) { $bbody .= $ad_text; } if ( $line =~ /Your E-Mail Address:/ ) { $bbody .= ""; } else { $bbody .= "$line"; } if ( $line =~ /subinfo.txt/ ) { open (STOP, "< $TOP_DIR/subinfo.txt"); my @slurp = ; foreach $what (@slurp) { $bbody .= $what; } } } # now submit to lyris $mid = &sendLyrisMail("bv-html-test", "$SUBJECT", "$REPLYTO", "$OURMAIL", "$bbody", "html", "$LIST.html"); print LOG "Message id: [$mid]\n"; if ( ! $mid ) { print LOG "ERROR: Message inject into lyris for $LIST has failed! [$mid]\n"; `/usr/local/bin/critsit "HTML $LIST [$mid] message into Lyris failed!"`; exit; } print LOG "Message inject successful NOT updating [$NUMBER_FILE].\n"; print LOG "Done.\n\n"; exit;