#!/usr/bin/perl -w # myrss.pl - by dual # # Generates custom BBC news feed ################################ use strict; use LWP::UserAgent; use XML::Simple; # Get and check args usage() unless defined (my $conf = shift); # Create the HTML open HTML, ">bbcnews.html" or die "Can't create HTML: $!"; print HTML < myRSS: BBC News My Way
myRSS BBC News
EOF # Read in the config file and # pass to download function open CONF, "<$conf" or die "Can't open config file: $!"; while () { download ($_); } # Close out the HTML print HTML <

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 HTML "Front Page News\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Africa/i) { $url = "$base/africa/rss.xml"; description_table(); print HTML "Africa\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Americas/i) { $url = "$base/americas/rss.xml"; description_table(); print HTML "Americas\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Asia-Pacific/i) { $url = "$base/asia-pacific/rss.xml"; description_table(); print HTML "Asia-Pacific\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Europe/i) { $url = "$base/europe/rss.xml"; description_table(); print HTML "Europe\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Middle East/i) { $url = "$base/middle_east/rss.xml"; description_table(); print HTML "Middle East\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /South Asia/i) { $url = "$base/south_asia/rss.xml"; description_table(); print HTML "South Asia\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /UK/i) { $url = "$base/uk_news/rss.xml"; description_table(); print HTML "UK\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Business/i) { $url = "$base/business/rss.xml"; description_table(); print HTML "Business\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Health/i) { $url = "$base/health/rss.xml"; description_table(); print HTML "Health\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Science\/Nature/i) { $url = "$base/science/nature/rss.xml"; description_table(); print HTML "Science/Nature\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Technology/i) { $url = "$base/technology/rss.xml"; description_table(); print HTML "Technology\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Entertainment/i) { $url = "$base/entertainment/rss.xml"; description_table(); print HTML "Entertainment\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Have Your Say/i) { $url = "$base/talking_point/rss.xml"; description_table(); print HTML "Have Your Say\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Magazine/i) { $url = "$base/uk_news/magazine/rss.xml"; description_table(); print HTML "Magazine\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Week At a Glance/i) { $url = "$base/week_at-a-glance/rss.xml"; description_table(); print HTML "Week At a Glance\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Programmes/i) { $url = "$base/programmes/rss.xml"; description_table(); print HTML "Programmes\n"; print HTML "\n\n\n\n\n"; } elsif ($rss =~ /Latest Published Stories/i) { $url = "$base/latest_published_stories/rss.xml"; description_table(); print HTML "Programmes\n"; print HTML "\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 HTML "+ $content->{channel}->{item}->[$cnt]->{description}
" if defined ($link); } print HTML "\n\n\n"; # End download } # Print the HTML for each description sub description_table { print HTML <
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; }