//depot/projects/slashbox/slashbox.pl#1 – add change 70 (xtext) ·revision history
| 1 | #!/usr/bin/perl |
| 2 | # slashbox.pl -- dump the latest headlines into /etc/motd.headlines so |
| 3 | # people have something to read while the ssh applet loads. |
| 4 | # zz9, may 2004 |
| 5 | # |
| 6 | # cron: */30 * * * * /usr/local/bin/slashbox.pl > /etc/motd.headlines |
| 7 | |
| 8 | use strict; |
| 9 | use LWP::Simple; |
| 10 | use XML::RSS; |
| 11 | |
| 12 | my @feeds = ( |
| 13 | [ 'Slashdot' => 'http://slashdot.org/index.rss' ], |
| 14 | [ 'Kuro5hin' => 'http://www.kuro5hin.org/backend.rdf' ], |
| 15 | [ 'BBC News' => 'http://news.bbc.co.uk/rss/newsonline_world_edition/front_page/rss091.xml' ], |
| 16 | ); |
| 17 | my $max = 5; |
| 18 | |
| 19 | print "--- ttul.org headlines, ", scalar(localtime), " ---\n\n"; |
| 20 | for my $f (@feeds) { |
| 21 | my ($name, $url) = @$f; |
| 22 | my $xml = get($url); |
| 23 | unless ($xml) { |
| 24 | print "[$name] (feed down. probably slashdotted. irony noted.)\n\n"; |
| 25 | next; |
| 26 | } |
| 27 | my $rss = XML::RSS->new; |
| 28 | eval { $rss->parse($xml) }; |
| 29 | if ($@) { |
| 30 | print "[$name] (bad XML)\n\n"; |
| 31 | next; |
| 32 | } |
| 33 | print "[$name]\n"; |
| 34 | my $n = 0; |
| 35 | for my $item (@{ $rss->{items} }) { |
| 36 | last if ++$n > $max; |
| 37 | my $t = $item->{title}; |
| 38 | $t =~ s/\s+/ /g; |
| 39 | $t = substr($t, 0, 72) . "..." if length $t > 75; |
| 40 | print " * $t\n"; |
| 41 | } |
| 42 | print "\n"; |
| 43 | } |