Contents |
Simple RSS Feed Aggregator
Introduction
The intentions of this example is to demonstrate how to aggregate RSS feeds using a three step process.
- Download one or many RSS feeds.
- Make the downloading of one or many RSS feeds periodic.
- Use the RSS Feed File Class to markup a RSS feed using XHTML and CSS.
How to Download one or many RSS Feeds
With your favorite text editor edit the get_rss_feeds.pl file, and look for the following lines.
my $rss_path = "/path/to/where/rss/feeds/get/downloaded/";
The $rss_path variable is a string that holds the path to where the RSS feeds are copied from the internet, to the server's filesystem. The $config_path variable is a string that holds the filename of the configuration file. The format of the configuration file is comma separated value (CSV), an example of the file format is shown below.
my $config_path = "/path/to/where/rss/feeds/file/is/located/rss_files";
#<RSS Feed URL>,<Filename of RSS Feed>
http://www.slashdot.org/slashdot.rdf,slashdot.rdf
http://blog.heatxsink.com/syndicate/index.xml,heatxsink.rss
So via the sample configuration file above the get_rss_feeds.pl perl script would download two rss feeds, as slashdot.rdf, and heatxsink.rss. The feeds after downloading would be located at whatever path the $rss_path string variable was set to.
To invoke the get_rss_feeds.pl perl script, type the following in a terminal window.
./get_rss_feeds.pl
How To Use the RSS Feed File Class
First you need to require the php file that contains the rssFeedFile class.
<?php require ("rss_feed_class.php"); ?>
Then within the body of your XHTML/HTML document instantiate the class, the default constructor takes a absolute or relative path, and can also take a URL to an RSS feed.
The code below points to a file that is located on the server where the webpages are being served up.
<?php
$rssFeed = new rssFeedFile("rss/nat.rss");
$rssFeed->parse(False);
$rssFeed->ReturnDiv(False, "feedTitle", "feed");
?>
The code below points to a URL of a RSS feed.
<?php
$rssFeed = new rssFeedFile("http://blog.heatxsink.com/syndicate/index.xml");
$rssFeed->parse(False);
$rssFeed->ReturnDiv(False, "feedTitle", "feed");
?>
Check the Example and Download Page for the rendered output of the above two examples.
Software Dependancies
- Perl
- PHP
- Cron
- Open Mind (optional)