Month: November 2003

  • Using Cron with LWP::Simple and XML::RSS to retrieve news feeds

    Originally published on March 24, 2003 when the war in Iraq was heating up and I found direct links to popular RSS news feeds were effecting the speed in which pages loaded on a friend’s blog whom I help maintain. I’m re-posting this article for reasons that will become obvious later this week. Until then, enjoy this “Spidering Hack!-)”

    Adding some syndicated news feeds is a nice way of adding some compelling content to your site.

    The problem is that sometimes the news feed gets overrun during heavy news days, go offline and/or suffers a host of other connectivity issues that make YOUR site load slow because the software holds your user hostage while the feed retrieval portion of the application has to wait to timeout. You see this alot with PHPNuke and PostNuke sites.

    A simple way around this problem is to use a program that periodically retrieves the feed, slices-n-dices and effectively caches it into an easy to include file on your host. Doing this achieves five goals:

    1. user page loads are not penalized when feeds go down
    2. failures to connect do not harm the existing include file
    3. multiple attempts to read the feed to not penalize user
    4. feed can be mirrored for local/private use
    5. content can be formatted to taste

    Below is a little program I wrote Thursday to grab news feeds from an AP Wire I found via Scripting.com for inclusion on a the website of a friend who makes his living in the political area.

    Using the following CRONTAB syntax, the program is executed every 30 minutes:
    30 * * * * /home/YOURPATH/getap.pl>/dev/null

    The nice thing about this approach is that this particular feed does “get busy” from time to time and at one point on Friday went offline. My users did not notice because in most cases, I was able to get by the “busy signal” on the 2nd or 3rd attempt out of 10. In the case where the feed site went offline, my users merely viewed and older include file without interruption or delay.

    Anyway, since I haven’t posted anything worthwhile in the past few days, I figured this was a good penance:

    #!/usr/bin/perl -w
    # ———————————————————————–
    # copyright Dean Peters © 2003 – all rights reserved
    # http://www.HealYourChurchWebSite.com
    # ———————————————————————–
    #
    # getap.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:
    # http://www.healyourchurchwebsite.com/archives/000002.shtml
    #
    # For more info. about this code, please refer to the following article:
    # http://www.healyourchurchwebsite.com/archives/000760.shtml
    #
    # combine this code with crontab for best results, e.g.:
    # 30 * * * * /home/YOURPATH/getap.pl>/dev/null
    #
    # ———————————————————————–
    use XML::RSS;
    use LWP::Simple;
    # get content from feed — using 10 attempts
      my $content = getFeed("http://www.goupstate.com/apps/pbcs.dll/section?Category=RSS04&mime=xml", 10);
    
    # save off feed to a file — make sure you have write access to file or directory
    saveFeed($content, "newsfeed.xml");
    
    # create customized output
    my $output = createOutput($content, 8);
    
    # save it
    saveFeed($output, "newsfeed.inc.php");
    sub getFeed {
         my ($url, $attempts) = @_;
         my $lc = 0;		# loop count
         my $content;
         while($lc $outfile") || die("Cannot Open File $outfile");
             print OUT $content;
         close(OUT);
    }
    sub createOutput {
         my ($content, $feedcount) = @_;
    
         # create new instance of XML::RSS
         my $rss = new XML::RSS;
    
         # parse the RSS content into an output string to be saved at end of parsing
         $rss->parse($content);
         my $title = $rss->{'channel'}->{'title'};
         my $output = "GoUpstate/AP NewsWire\n";
         my $i = 0;
         foreach my $item (@{$rss->{'items'}}) {
             next unless defined($item->{'title'}) && defined($item->{'link'});
             $i += 1;
             next if $i > $feedcount;
             $output .= "<a>{'link'}\"&gt;$item-&gt;{'title'}</a>\n";
         }
    
        # if a copyright &amp; link exists then post it
        my $copyright = $rss-&gt;{'channel'}-&gt;{'copyright'};
        my $link = $rss-&gt;{'channel'}-&gt;{'link'};
        my $description = $rss-&gt;{'channel'}-&gt;{'description'};
        $output .= "  <a>$copyright</a>\n"	if($copyright &amp;&amp; $link);
        $output .= "";
        return $output;
    }
    

    Of course, now I need to go ahead and practice what I preach and do the same here!

  • ‘Confusion’ about the Body online

    What a great week. You guys (and gals) have really carried the ball in some excellent discussions of what it takes behind the scenes to get and keep the content on your church website current and compelling. As you can see, I just sat back and took it all in … which is good because it was the last comment by Ken at Apex Community Church that got me thinking when he wrote:

    We decided to take the approach that our website was an extension of Sunday morning and Wednesday night. Just like we wouldn’t just hand the microphone to just anyone then, we don’t just hand the “keyboard” to anyone on the web. And, in reality, we do. We just take time to approve it. Any issues that arise from this aren’t just swept under the rug, we just deal with them offline.

    This reminded of the Apostle Paul mentioned in his first letter to the Corinthians when dealing with the issue of order with regards to the public use of Spiritual Gifts, in which the man from Tarsus writes:

    For God is not a God of disorder but of peace. – 1 Corinthians 14:33 NIV

    For God is not a God of confusion but of peace. – 1 Corinthians 14:33 ESV

    With that in mind, what approach then should we take to publishing content online? Should we as webservants become the singular conduit for getting information online, thereby creating a bottle-neck from a single point of view? Or should we open the gates wide and allow anyone to post anything on any topic without regards to the purpose and personality of the church?

    Yes, I realized I just cited the radical extremes, but in showing them, I’m hoping we can all figure out some middle ground. For example, do we offer forums for prayer requests? If so, do we moderate them so we don’t have people dominating it with requests for their kitten with the sniffles? Similarly, I mentioned getting staff involved, but not all staff is all things to all people … or websites. Is it wise to cut them loose, or worse, let some post their own content why denying others?

    Again, I’d be very interested in your responses. Oh yeah, and about that. They’ve all been sooooo good I suspect this weekend I’m going to pick and summarize some in some sort of post so you can discuss these on your own blogs as I think the more we talk about it, the wiser we become as a Body online.

    Thanks again for all the intelligent, thoughtful and respectful debate. You make running HYCW such a joy!

  • Using Wget to download large distributions

    It’s 11:59pm, I’m slouched in front of my computer thinking about a topic for tomorrow while in the background, I’ve initiated the all-night download of the most recent version of Knoppix, all 700 megabytes of it. Hey, if the Senate can stay up spinning their wheels, so can my computer? Provided that the high winds here near D.C. don’t blow down my DSL connection …

    … hey wait … Congress is up all night talking … high winds here in Rockville … Canadian cold front my eye! … but I digress ..

    Anyway, with the weekend upon us, I thought that those of you looking to download and burninate the latest and greatest distro of Fedora, OpenOffice or some other Linux-based fun, might not be aware that you can use Wget to download large applications … even when blowhards break your connection intermittently.

    For those of you who don’t know, GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs and in my case, a batch file.

    By using this Wget with the –continue command to resume getting a partially-downloaded file after getting disconnected, in combination with the –no-clobber directive not to delete existing files … like the partially-downloaded I’ve been downloading all night … I can begin a download at 8pm, and then wake-up at 8am without worrying about disconnections during the time in between.

    Below is an example of this in the form of a batch file I created on my Win2k machine to download Knoppix … a script that could just as easily be implemented in bash (just ignore the linewrap):

    wget -nc -c http://mirror.csit.fsu.edu/knoppix/KNOPPIX_V3.3-2003-11-03-EN.iso
    wget -nc -c http://mirror.csit.fsu.edu/knoppix/KNOPPIX_V3.3-2003-11-03-EN.iso.md5
    wget -nc -c http://mirror.csit.fsu.edu/knoppix/KNOPPIX_V3.3-2003-11-03-EN.iso.md5.asc
  • Church Sign Generator

    Church Sign Generatorclick here and generate your own sign from God
    Here is a link to a little bit of Friday Fun, the Church Sign Generator. You enter text into four fields, press the ‘Go’ buttona and PRESTO … it re-draws a picture of a First Baptist roadside sign-from-God with your own compelling ‘n’ kitchy come-to-church slogans … sorta like the ones the author of the program lists on his own blog.

    How is this miracle of web wizardry achieved? I suspect the coder behind this fun read some sort of book or article on how to “Create graphics on the fly using PHP,” … or at least read the Image Functions section of the PHP manual.

    Man-o-man … does this give me a funny idea …