Evil Perl Scripts’O’Doom
Here are a couple of very petite scripts I’ve written to fulfill very specific needs. I might add to them, but I don’t need anything right now.
1. Searchenginator.
I don’t know where this script is. So forget I mentioned it.
2. Happy Log Entry Thing.
Likewise, forget I said anything.
3. Luscious RSS Parsing Goodness
These both do more or less the same thing – which is parse an RSS file and output HTML – they’re both here, and they’re both as messy as fuck, and commented badly etc, because I’m stuffed if I can be bothered sorting them out right now. (It’s Christmas Eve, you see).
Either can be used, probably. news.pl will definitely work, but you’ll have to find the RSS file yourself, Moreover can provide one, no doubt. You can either use an SSI to execute the script, which will then include the resultant HTML in your document, or you can use a shell script (on a cron, perhaps) to run it every 30 minutes or 2 hours, or whatever seems appropriate, pipe the HTML into a file, then include that in your document.
Whatever you do, let me know. I’d be very interested to hear if anyone finds this interesting at all. I don’t remember where I got the original file I built this on, might have been from IBM or someone. *shrug*.
news.pl |
#!/usr/bin/perl # Load the XML::RSS module. use XML::RSS; # User agent object. use LWP::UserAgent; $ua = new LWP::UserAgent; # Set the name of the RSS file to parse $rss_file = "/var/www/feeds/rss/nznews.rss"; # Print the start of the HTML #print "Content-type: text/htmlnn"; #print <<_END_; #<html> # <head> # <title>RSS Example</title> # </head> # <body> #_END_ # Create an instance of the XML::RSS class. my $rss = new XML::RSS; # Parse the RSS file $rss->parsefile($rss_file); # Start printing a little table to # hold the RSS news headlines print qq{<table border="0">}; # Print a link that goes to the RSS channel's URL, # with the channel's name. #print qq{ <tr><td align="center">}; #print qq{<a href="$rss->{'channel'}{'link'}">}; #print $rss->{'channel'}{'title'}; #print "</a></td></tr>n"; # Go through each of the news items my $foo = 0; for my $item (@{$rss->{items}}) { print " <tr><td><img src="/images/blub.gif" border=0 alt="*">"; # Create user agent request my $req = new HTTP::Request POST => $item->{'link'}; # Pass request to the user agent and get a response back my $res = $ua->request($req); my $goto = ${$res->headers}{"location"}; # Print a link that goes to the news article, with # the headline as the name print qq{<a href="$item->{'link'}" target="_new">}; print $item->{'title'}; print "</a>"; print "</td></tr>n"; last if (++$foo == 30); } # End the table and HTML print <<_END_; </table> _END_ # <body> #<html> |
mingus.pl |
#!/usr/bin/perl # Load the XML::RSS module. use XML::RSS; # User agent object. use LWP::UserAgent; $ua = new LWP::UserAgent; # Set the name of the RSS file to parse $rss_file = "/var/www/feeds/rss/rss/technology.rss"; # Create an instance of the XML::RSS class. my $rss = new XML::RSS; # Parse the RSS file $rss->parsefile($rss_file); # Start printing a little table to # hold the RSS news headlines print qq{<table border="0">}; # Go through each of the news items my $foo = 0; for my $item (@{$rss->{items}}) { print " <tr><td><img src="/images/blub.gif" border=0 alt="*">"; ########################### # Create user agent request my $req = new HTTP::Request POST => $item->{'link'};
# Pass request to the user agent and get a response back my $res = $ua->request($req); my $goto = ${$res->headers}{"location"}; # Check response # if ($res->is_success) { # my $goto = $req; # } else { # my $goto = ${$res->headers}{"location"}; # } # ########################## # Print a link that goes to the news article, with the headline as the name print (get $item->{'title'}); # print qq{<a href="$item->{'link'}" target="_new">}; print qq{<a href="$goto" target="_new">}; print $item->{'title'}; print "</a></td></tr>n"; last if (++$foo == 2); } # End the table and HTML print <<_END_; </table> _END_ # <body> #<html>
|