We Recommend

Learning Perl Learning Perl
In this smooth, carefully paced course, a leading Perl trainer teaches you to program in the language that threatens to make C, sed, awk, and the Unix shell obsolete for many tasks. This book is the "official" guide for both formal (classroom) and informal learning. It is fully accessible to the novice programmer.


Posted By

noah on 07/03/07


Tagged

http rss html xml web atom 2003 publish aggregator community homepage suburbanangstcom


Versions (?)


Aggregate RSS feeds


Published in: Perl 


Expects a newline-delimited list of RSS feed urls. Prints an HTML 4 page containing a grid of modules. The modules contain hyperlinked feed headlines.

Very fragile, any invalid feed will break the whole aggregator.

  1. #! /usr/bin/perl -w
  2. BEGIN {
  3. unshift(@INC, "/home/suburban/public_html/yubaba");
  4. # Add the directory where this file is to the beginning of @INC
  5. }
  6.  
  7. use strict;
  8. use CGI qw(:standard);
  9. use RSS2html;
  10. use NoFace; #old script to scrape weather.com. broken.
  11.  
  12. #yubaba.pl is the RSS feed script it should be run by a cron job every half-hour or so.
  13. #sussman may 03
  14.  
  15. #****************************************************************
  16. # REMEMBER TO REMOVE SLASHDOT FROM rssList.txt BEFORE TESTING! *
  17. #****************************************************************
  18.  
  19. #MAIN
  20.  
  21.  
  22. my $rss_feeds = "/home/suburban/public_html/yubaba/rssList.txt"; #List of RSS uris, one per line
  23. my $non_rss = "/home/suburban/public_html/yubaba/nonRss.txt";
  24. my $parser = new rss2html;
  25. my $grab = new NoFace;
  26.  
  27. my $display = new CGI;
  28.  
  29. #my %syndicate = $grab -> get_facts ($non_rss);
  30. #wtr_high, wtr_low, wtr_cloud_condition, wtr_tomorrow_temp, wtr_tomorrow_cloud
  31.  
  32.  
  33.  
  34. #print $display->header;
  35. #print start_html(-title=>'suburbanangst.com: news',
  36. # -head=>Link({-rel=>"stylesheet",
  37. # -href=>"http://suburbanangst.com/style.css"})
  38. # );
  39. print start_html(-title=>'suburbanangst.com: news',
  40. -head=>
  41. Link(
  42. {
  43. -rel=>"stylesheet",
  44. -href=>"http://suburbanangst.com/style.css"
  45. }
  46. ),
  47. -script=>
  48. {
  49. type=>"text/javascript",
  50. code=>'setTimeout("window.location.reload(true)", 900*1000); // refresh time in ms'
  51. }
  52. );
  53.  
  54. print <<HTML;
  55. <table width="100%">
  56. <tr>
  57. <td style="text-align: center;"><a href="bookmarks.html">Bookmarks</a> ||
  58. <a href="http://onemorebug.com">OneMoreBug.com</a> ||
  59. <a href="http://tommyz.net">TommyZ.net</a> ||
  60. <a href="http://OneMoreBug.com/">Web Design Seminar</a> || <a href="/PL/">Perl Scripts</a>
  61. </td>
  62. </tr>
  63. <tr>
  64. <td style="text-align: center;"><a href="help/">Resources</a> ||
  65. <a href="game/">GURPS Teleria</a>
  66. </td>
  67. </tr>
  68. <tr>
  69. <td style="text-align: center;">
  70. <h3>Welcome to Suburban Angst!</h3>
  71. </td>
  72. </tr>
  73. HTML
  74.  
  75. print "<tr><td style=\"text-align: center;\">";
  76.  
  77. print "</td></tr><tr><td style=\"text-align: center;\"><a href=\"http://www.srh.noaa.gov/data/forecasts/NYZ072.php?warncounty=NYC061&city=New+York\">Weather</a> || <a href=\"http://nyt.com\">New York Times</a> || <a href=\"http://google.com\">Google</a> || <a href=\"http://h2odev.law.harvard.edu/ezuckerman/\">Google Map</a>";
  78.  
  79. print "<p></p><!-- <p style=\"text-align: center;\">Last updated ";
  80. print " PST<p/> gotta fix this! -->";
  81.  
  82. #THE KKK TOOK MY WEATHER CHANNEL AWAY
  83. #print "<p>$syndicate{'wtr_cloud_condition'}, <b>$syndicate{'wtr_high'}</b>, High/Low: <b>$syndicate{'wtr_low'}.</b> Precip: <b>$syndicate{'wtr_precip'}.</b> <i>Tomorrow:</i> $syndicate{'wtr_tomorrow_cloud'}, $syndicate{'wtr_tomorrow_temp'}, precip: $syndicate{'wtr_tomorrow_precip'}.</p>";
  84.  
  85. print "<a href=\"http://dailyrotten.com\">Daily Rotten</a> || <a href=\"http://consumptionjunction.com/content/browse.asp?type=8\">Consumption Junction Daily</a> || <a href=\"http://freshnews.org\">FreshNews</a></p>";
  86.  
  87.  
  88.  
  89. print "</td></tr></table>\n";
  90.  
  91. print <<HTML;
  92. <table cellspacing="10" width="60%%" align="center">
  93.  
  94. HTML
  95.  
  96. render($rss_feeds);
  97.  
  98. print <<HTML;
  99. </table>
  100. HTML
  101.  
  102. print $display->end_html;
  103.  
  104.  
  105.  
  106. #****************************************************************
  107. # SUBROUTINES *
  108. #****************************************************************
  109.  
  110. sub render {
  111. $ARGV[0] = shift; #argument is my RSS feeds
  112. my $counter = 0; #counts the number of boxes
  113. my $other_counter = 0; #counts the number of boxes in a column
  114. my $number_of_entries = 0; #must be an even number. half the entries go in one column, half in the other. overflow entries span the whole screen.
  115. #****************
  116. #Assumes we are reading a file with one URL on each line
  117. #****************
  118. while (<>) {
  119. chomp(my $url = $_);
  120.  
  121. if ($url ne "") {
  122. if ($counter == 0) { print "<tr><!--1a-->";
  123. }
  124.  
  125. if ($other_counter == 0) {
  126. print '<td class="blogborder"><!--2a-->';
  127. }
  128.  
  129.  
  130. $parser -> rss_get ($url);
  131.  
  132.  
  133. if ($other_counter >= ($number_of_entries / 2) -1) {
  134. print "<!--2b--></td>";
  135. $other_counter = 0;
  136. }
  137. else {
  138. ++$other_counter;
  139. }
  140.  
  141. if ($counter >= ($number_of_entries) -1 ) {
  142. print "</tr><!--1b-->";
  143. $counter = 0;
  144. }
  145. else {
  146. ++$counter;
  147. }
  148. }
  149. }
  150. }

Report this snippet 

You need to login to post a comment.