It dawned on me how often I mention that I’m a coder, without having really shown you all that much useful code. So I sat down at my trusty new computer, after my daughter rousted me at 5am, and 20 minutes later, I had a program I’ve wanted to write to provide Redland Baptist some more compelling content. A daily scripture verse that is modified automatically.
A potential problem created by the insidious varieties of <font> and <center> tags inflicted upon the output, is that such tags get in way of my not-so-evil plans to stash this verse in XML so I can dynamically render it to a wide variety of platforms. No, the solution was obvious, I had to find a relatively unpolluted stream of data, screen-scrape it, then render it so it fit my site’s personality and formatting style, while still rendering unto Ceaser what is his. To do it automatically in the middle of the night has me thinking of my old friend Perl and its forward thinking friend cron.
# copyright Dean Peters © 2002 – all rights reserved
# versescrape.pl is free software. You can redistribute and modify it
# freely without any consent of the developer, Dean Peters, if and
# only if the following conditions are met:
# (a) The copyright info and links in the headers remains intact.
# (b) The purpose of distribution or modification is non-commercial.
# Commercial distribution of this product without a written
# permission from Dean Peters is strictly prohibited.
# This script is provided on an as-is basis, without any warranty.
# The author does not take any responsibility for any damage or
# loss of data that may occur from use of this script.
# You may refer to our general terms & conditions for clarification
# The good folks at the IBS asked us to include the following disclaimer:
# THIS SITE/SERVICE IS PROVIDED BY IBS ON AN “AS IS” BASIS, AND IBS MAKES
# NO REPRESENTATION OR WARRANTIES OF ANY KIND, EXPRESSED OR IMPLIED, AS TO
# THE OPERATION OF THE SITE OR THE INFORMATION, CONTENT, MATERIALS, OR
# PRODUCTS INCLUDED ON THIS SITE. TO THE FULL EXTENT PERMISSIBLE BY
# APPLICABLE LAW, IBS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
# INCLUDING FITNESS FOR A PARTICULAR PURPOSE. IBS WILL NOT BE LIABLE FOR
# ANY DAMAGES OF ANY KIND ARISING FROM THE USE OF THIS SITE, INCLUDING,
# BUT NOT LIMITED TO, DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, AND
# CONSEQUENTIAL DAMAGES.
# See also http://www.ibs.org/bibles/termsofuse.php
# ——— name of the output file ———–
# * change the path and output file to suit your system
# * make sure it exists, and is chmod’ 766 or 777
$verseFile = “/home/YOURACCCOUNT/www/includes/dailyverse.html”;
# ——— url containing the daily scripture verse ———
# ——— url of online scripture lookup:
# ——— get the scripture ———
$content = get($scriptureURL);
$content =~ s/^document\.writeln\(“//gi;
$content =~ s/ NIV\)”\)\;//gi;
# ——— split content into verse & reference ———
($verse, $reference) = split(/\(/, $content);
# ——— create output ———
$bibleURL .= $reference;
$bibleURL = qq~<a href=”$bibleURL” title=”NIV – Bible Gateway”>$reference</a>~;
# ——— print output ———–
$output = qq~<div class=”dailyScripture”>
<br /><br />
<a href=”http://www.ibs.org/” title=”International Bible Society © 2002″><span class=”credits”>Provided by International Bible Society</span></a>
<a href=”http://www.ibs.org/dm/” title=”SubScribe to the IBS Daily Verse”><span class=”credits”>Subscribe</span></a>
# ——— write output ————
open(OUT,”>$verseFile”) || die(“Cannot Open File $verseFile”);
print OUT $output;
- Using your favorite editor, copy and paste the above code.
- edit $verseFile so the path and filename reflect YOUR system’s settings
- save the file
- chmod 755 versescrape.pl (set permission)
- create an empty file using the name defined by $verseFile
- set the permissions of the target output file to 766 or 777
- run the script once from the shell – test for errors
- crontab to taste
- include the verse file in your documents
- edit your .css documents to accomodate the <div> containing the reference
Keep in mind, this particular version has been written NOT as a .CGI script, but as a small script that will get called early in the morning by cron to create an output file that will be included on other documents via SSI or some similar mechanism.
Not bad for an early Monday morning, huh?
Posted by Dean at July 22, 2002 01:00 PM