chiark / gitweb /
more tweaks:
authorW. Ross Younger <ryounger@chiark.greenend.org.uk>
Sat, 11 Dec 2010 21:44:24 +0000 (21:44 +0000)
committerW. Ross Younger <ryounger@chiark.greenend.org.uk>
Sat, 11 Dec 2010 21:44:24 +0000 (21:44 +0000)
cope with degrees and rogue CRLFs in feed.
ignore items with empty titles.
re-enable IRC colouring (except in test mode)
don't cane the server in test mode.

TODO
rss2irc.pl
sites

diff --git a/TODO b/TODO
index 2142fd2..b8a32d9 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,5 @@
 Add better global config (botconf.pm?)
 Add msg handling (possibly allowing config to be rewritten?)
 
-Change feed list?  http://news.bbc.co.uk/1/hi/help/rss/default.stm so far.
+Tweak handling to cope with BBC weather feeds, which don't change their
+links (so would fall foul of the current cacheing logic).
index 6827999..de2b7c2 100644 (file)
@@ -123,6 +123,8 @@ sub cheat_encode($) {
     $_=shift;
     s/\xA3/GBP/g; # Pound signs choke some clients
     s/\xA4/EUR/g;
+    s/\xB0//g; # Degree
+    s/\n//g; # grr crlf
     s/[^ -~]/?/g;
     s/\?\s+//g;
     if (0) {
@@ -158,9 +160,13 @@ sub get_news {
                         # XXX Cheesy encoding in the absence of Encode.pm
                         #my $title = Encode::encode("iso-8859-1", $rss->{items}->[$i]->{title});
                         my $title = cheat_encode($rss->{items}->[$i]->{title});
+                        next unless $title ne "";
 
-                        #$site  = '\ 3'.$item->[1].$item->[0].'\ f: ';
-                        $site  = ''.$item->[0].': ';
+                        if ($TEST) {
+                            $site  = ''.$item->[0].': ';
+                        } else {
+                            $site  = '\ 3'.$item->[1].$item->[0].'\ f: ';
+                        }
                         #my $tmplink = $rss->{'items'}->[$i]->{'link'};
                         #$tmplink =~ s/^\s+//; $tmplink =~ s/\s+$//;
                         #$tmplink =~ s,^(http://news.bbc.co.uk/)go/rss/-/(.*),$1$2,;
@@ -220,7 +226,7 @@ sub update_cache {
     # so @_ is now the new cache. OVERWRITES what's already there!
     my $fh;
     my $cachefile = $cachedir."/".$name;
-    open($fh, ">", $cachefile) or die ("Cant open cachefile: $!");
+    open($fh, ">", $cachefile) or die ("Can't open cachefile: $!");
     print $fh $_.$/ for (@_);
     close($fh);
 }
@@ -290,5 +296,6 @@ $SIG{__DIE__} = \&deathexcept;
 while (1) {
     check_status($conn);
     $irc->do_one_loop();
+    sleep $checktime if $TEST;
 }
 
diff --git a/sites b/sites
index c63021f..7dd4034 100644 (file)
--- a/sites
+++ b/sites
@@ -5,3 +5,9 @@ bbc-world;0;http://feeds.bbci.co.uk/news/world/rss.xml
 bbc-biz;0;http://feeds.bbci.co.uk/news/business/rss.xml
 bbc-sci;0;http://feeds.bbci.co.uk/news/science_and_environment/rss.xml
 bbc-tech;0;http://feeds.bbci.co.uk/news/technology/rss.xml
+# Weather feeds never change their URLs, so the current code won't report them more than once. TODO, someday...
+#Cambridge;2;http://newsrss.bbc.co.uk/weather/forecast/324/ObservationsRSS.xml
+#Cambridge;2;http://newsrss.bbc.co.uk/weather/forecast/324/Next3DaysRSS.xml
+#Oxford;3;http://newsrss.bbc.co.uk/weather/forecast/25/ObservationsRSS.xml
+#Oxford;3;http://newsrss.bbc.co.uk/weather/forecast/25/Next3DaysRSS.xml
+