#!/usr/bin/perl -w # myrss-CGI.pl - by dual # # Generates custom BBC news feed # - CGI Version ################################ use strict; use LWP::UserAgent; use XML::Simple; # Create the HTML print "Content-type: text/html\r\n\r\n"; print < myRSS: BBC News My Way
myRSS BBC News
EOF # Read in the config file and # pass to download function open CONF, ") { download ($_); } # Close out the HTML print <

powered by backstage.bbc.co.uk

2005, myRSS
Not licensed under the
Creative Commons Public Domain Dedication.
EOF # Begin download function sub download { # Figure out which feed to get my $rss = $_[0]; my $base = 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition'; my $cnt; my $link; my $num; my $url; $rss =~ s/(\d+)//; oops() unless defined ($num = $1); if ($rss =~ /News Front Page/i) { $url = "$base/front_page/rss.xml"; description_table(); print "Front Page News\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Africa/i) { $url = "$base/africa/rss.xml"; description_table(); print "Africa\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Americas/i) { $url = "$base/americas/rss.xml"; description_table(); print "Americas\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Asia-Pacific/i) { $url = "$base/asia-pacific/rss.xml"; description_table(); print "Asia-Pacific\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Europe/i) { $url = "$base/europe/rss.xml"; description_table(); print "Europe\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Middle East/i) { $url = "$base/middle_east/rss.xml"; description_table(); print "Middle East\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /South Asia/i) { $url = "$base/south_asia/rss.xml"; description_table(); print "South Asia\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /UK/i) { $url = "$base/uk_news/rss.xml"; description_table(); print "UK\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Business/i) { $url = "$base/business/rss.xml"; description_table(); print "Business\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Health/i) { $url = "$base/health/rss.xml"; description_table(); print "Health\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Science\/Nature/i) { $url = "$base/science/nature/rss.xml"; description_table(); print "Science/Nature\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Technology/i) { $url = "$base/technology/rss.xml"; description_table(); print "Technology\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Entertainment/i) { $url = "$base/entertainment/rss.xml"; description_table(); print "Entertainment\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Have Your Say/i) { $url = "$base/talking_point/rss.xml"; description_table(); print "Have Your Say\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Magazine/i) { $url = "$base/uk_news/magazine/rss.xml"; description_table(); print "Magazine\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Week At a Glance/i) { $url = "$base/week_at-a-glance/rss.xml"; description_table(); print "Week At a Glance\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Programmes/i) { $url = "$base/programmes/rss.xml"; description_table(); print "Programmes\n"; print "\n\n\n\n\n"; } elsif ($rss =~ /Latest Published Stories/i) { $url = "$base/latest_published_stories/rss.xml"; description_table(); print "Programmes\n"; print "\n\n\n\n\n"; } else { oops(); } # Get the entire RSS feed my $browser = LWP::UserAgent->new(); my $feed = $browser->get ($url); die $feed->status_line . "\n" unless $feed->is_success; # Read in the XML my $content = XMLin($feed->content); # Output the given number of descriptions for ($cnt = 0; $cnt < $num; $cnt++) { $link = $content->{channel}->{item}->[$cnt]->{link}; print "+ $content->{channel}->{item}->[$cnt]->{description}
" if defined ($link); } print "\n\n\n"; # End download } # Print the HTML for each description sub description_table { print <
EOF } # Provide assistance sub usage { print < Feeds >>>>> News Front Page Africa Americas Asia-Pacific Europe Middle East South Asia UK Business Health Science/Nature Technology Entertainment Have Your Say Magazine Week At a Glance Programmes Latest Published Stories Simply create a configuration file with the names of the feeds you want and the number of latest stories, and you'll get an HTML file with all the news _you_ want to read. For example, News Front Page 2 Technology 1 will grab the two latest front page stories, and the latest technology story. It's that easy. There's more than one way to automate running this script, so it's left to the user. Enjoy! EOF exit; } # Help with the config file sub oops { print "\nOops! Something's not right in the config file...\n\n"; print "Run myRSS.pl without any arguments, i.e. perl myRSS.pl,\n"; print "to see all of the BBC feeds and verify file format.\n\n"; exit; }