#!/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; use rlib '../../../mod-lib'; use di; my $dntk = new dntk; $lyris::config_filename = "/opt/lyris/cgi/lyris.plc"; my $rc = &lyris::init; $| = 1; $DEBUG = 1; # TOP_DIR hack $TOP_DIR = "${TOP_DIR}/n_bv"; $N_DATE = &UnixDate('today', '%m-%d-%Y'); #$N_DATE = "08-30-04"; #$AD_DATE = "2004-08-30"; # MMDDYY # %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 "-> NF: $NUMBER_FILE\n"; 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: Bible Verses - $LINE1 - $N_DATE"; print "subj $SUBJECT\n"; #exit; # $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 $index; # jim's version of SSI... print "template: $TOP_DIR/template.html\n"; #exit; open (INDEX, "< $TOP_DIR/template.html"); my @file = ; foreach $line (@file) { if ( $line =~ /daily.html/ ) { $bbody .= "$page"; $index .= "$page"; } elsif ( $line =~ /simpletop.html/ ) { open (STOP, "< $TOP_DIR/simpletop.html"); my @slurp = ; foreach $what (@slurp) { if ( $what =~ /timestamp/ ) { $what =~ s/timestamp/$timestamp/g; } $bbody .= $what; $index .= $what; } } elsif ( $line =~ /ad.html/ ) { $bbody .= $ad_text; $index .= $ad_text; } elsif ( $line =~ /Your E-Mail Address:/ ) { $bbody .= ""; } elsif ( $line =~ /<\/body>/ || $line =~ /<\/BODY>/ ) { open (STOP, "< $TOP_DIR/subinfo.txt") || die "Cannot open [$TOP_DIR/bibleverses/subinfo.html]\n"; @slurp = ; close (STOP); foreach $what (@slurp) { # print "what: $what"; $bbody .= $what; } } else { $bbody .= "$line"; $index .= "$line"; } } my $idx = &insert_ads($index, $dntk, $AD_DATE, "bv-html"); open(I_INDEX, "> ${TOP_DIR}/index.shtml") || die "error index.shtml: [$!]\n"; print I_INDEX $idx; close I_INDEX; my $ad_body = &insert_ads($bbody, $dntk, $AD_DATE, "bv-html"); my $bbody = $ad_body; # now submit to lyris $mid = &sendLyrisMail("bv-html", "$SUBJECT", "$REPLYTO", "$OURMAIL", "$bbody", "html", "$LIST.html"); #$mid = &sendLyrisMail("bv-html-test", "TEST - $SUBJECT", "$REPLYTO", "$OURMAIL", "$bbody", "html", "$LIST.html"); #print LOG "Message id: [$mid]\n"; print "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;