2 # RSSTest.pl: RSS Tractker hacked from Plug.pl/Rss.pl
3 # Author: Dan McGrath <djmcgrath@users.sourceforge.net>
4 # Licensing: Artistic License (as perl itself)
13 use vars qw(%channels %param $dbh $who $chan);
16 my ( $file, $url ) = @_;
19 &::DEBUG("rssFeed: Searching cache for $url");
21 open CACHE, "<$file" or return;
22 binmode( CACHE, ":encoding(UTF-8)" );
36 my ( $file, $url, @entries ) = @_;
38 open IN, "<$file" or return;
39 open OUT, ">$file.tmp" or return;
41 binmode( IN, ":encoding(UTF-8)" );
42 binmode( OUT, ":encoding(UTF-8)" );
44 # copy all but old ones
52 print OUT "$url:$_\n";
58 rename "$file.tmp", "$file";
64 &::status("rssFeed: Creating cache in $file");
66 open CACHE, ">$file" or return;
71 my ( $cacheFile, $chan, $rssFeedUrl ) = @_;
73 &::DEBUG("rssFeed: URL: $rssFeedUrl");
75 my $feed = XML::Feed->parse( URI->new($rssFeedUrl) )
76 or return XML::Feed->errstr;
78 my $curTitle = $feed->title;
79 &::DEBUG("rssFeed: TITLE: $curTitle");
82 for my $entry ( $feed->entries ) {
83 &::DEBUG( "rssFeed: ENTRY: " . $entry->title );
84 push @curEntries, $entry->title;
87 # Create the cache if it doesnt exist
88 &createCache($cacheFile)
89 if ( !-e $cacheFile );
91 my @oldEntries = &getCacheEntry( $cacheFile, $rssFeedUrl );
93 foreach (@curEntries) {
94 &::DEBUG("rssFeed: CACHE: $_");
95 last if ( $_ eq $oldEntries[0] );
99 if ( scalar @newEntries == 0 ) { # if there wasn't anything new
100 return "rssFeed: No new headlines for $curTitle.";
104 &saveCache( $cacheFile, $rssFeedUrl, @curEntries )
105 or return "rssFeed: Could not save cache!";
107 my $reply = &::formListReply( 0, $curTitle, @newEntries );
108 &::msg( $chan, $reply );
110 # "\002<<\002$curTitle\002>>\002 " . join( " \002::\002 ", @newEntries ) );
117 my $cacheFile = "$::param{tempDir}/rssFeed.cache";
120 if ( not $command =~ /^(flush|update)?$/i ) {
121 &::status("rssFeed: Unknown command: $command");
125 if ( $command =~ /^flush$/i ) {
126 if ( not &::IsFlag("o") ) {
128 "rssFeed: User $::who tried to flush the cache, but isn't +o!");
131 unlink $cacheFile if ( -e $cacheFile );
132 &::status("rssFeed: Flushing cache.");
133 &::performStrictReply("$::who: Flushed RSS Feed cache.");
137 if ( $command =~ /^update$/i ) {
138 if ( not &::IsFlag("o") ) {
140 "rssFeed: User $::who tried to manually update feeds, but isn't +o!"
144 &::status("rssFeed: Manual update of feeds requested by $::who.");
147 foreach my $chan ( keys %::channels ) {
148 my $rssFeedUrl = &::getChanConf( 'rssFeedUrl', $chan );
149 my @urls = split / /, $rssFeedUrl;
151 # Store by url then chan to allow for same url's in multiple channels
152 foreach (@urls) { $feeds{$chan}{$_} = 1 }
155 foreach my $chans ( keys %feeds ) {
156 foreach ( keys %{ $feeds{$chans} } ) {
157 my $result = &getFeed( $cacheFile, $chans, $_ );
158 &::status($result) if $result;
166 # vim:ts=4:sw=4:expandtab:tw=80