--- trunk/bin/irc-logger.pl 2008/03/07 00:18:02 87
+++ trunk/bin/irc-logger.pl 2008/03/07 10:13:45 91
@@ -20,12 +20,6 @@
=item --log=irc-logger.log
-Name of log file
-
-=item --follow=file.log
-
-Follows new messages in file
-
=back
=head1 DESCRIPTION
@@ -50,13 +44,8 @@
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);
my $IRC_ALIAS = "log";
-# default log to follow and announce messages
-my $follows_path = 'follows.log';
-
my $DSN = 'DBI:Pg:dbname=' . $NICK;
-# log output encoding
-my $ENCODING = 'ISO-8859-2';
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
my $sleep_on_error = 5;
@@ -74,10 +63,9 @@
## END CONFIG
-use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP);
+use POE qw(Component::IRC Component::Server::HTTP);
use HTTP::Status;
use DBI;
-use Encode qw/from_to is_utf8/;
use Regexp::Common qw /URI/;
use CGI::Simple;
use HTML::TagCloud;
@@ -100,7 +88,6 @@
my $log_path;
GetOptions(
'import-dircproxy:s' => \$import_dircproxy,
- 'follows:s' => \$follows_path,
'log:s' => \$log_path,
);
@@ -111,29 +98,9 @@
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";
sub _log {
- my $out = strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/;
- from_to( $out, 'UTF-8', $ENCODING );
- print $out;
+ print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/;
}
-# LOG following
-
-my %FOLLOWS =
- (
-# ACCESS => "/var/log/apache/access.log",
-# ERROR => "/var/log/apache/error.log",
- );
-
-sub add_follow_path {
- my $path = shift;
- my $name = $path;
- $name =~ s/\..*$//;
- warn "# using $path to announce messages from $name\n";
- $FOLLOWS{$name} = $path;
-}
-
-add_follow_path( $follows_path ) if ( -e $follows_path );
-
# HTML formatters
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
@@ -177,6 +144,7 @@
};
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
+$dbh->do( qq{ set client_encoding = 'UTF-8' } );
my $sql_schema = {
log => qq{
@@ -533,7 +501,6 @@
return unless ($arg->{id} && $arg->{message});
my $m = $arg->{message};
- from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m));
my @tags;
@@ -675,18 +642,17 @@
}
my $msg;
- $msg .= prefix( 'From: ' , $feed->title );
+ $msg .= prefix( 'From: ' , $args->{name} || $feed->title );
$msg .= prefix( ' by ' , $entry->author );
$msg .= prefix( ' -- ' , $entry->link );
# $msg .= prefix( ' id ' , $entry->id );
if ( $args->{kernel} && $send_rss_msgs ) {
- warn "# sending to $CHANNEL\n";
$send_rss_msgs--;
+ _log('RSS', $msg);
+ $sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, undef );
$args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg );
$updates++;
- #$sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, undef );
- _log('RSS', $msg);
}
}
@@ -725,7 +691,7 @@
my $kernel = shift;
my $last_t = $_rss->{last_poll} || time();
my $t = time();
- if ( $last_t - $t > $rss_min_delay ) {
+ if ( $t - $last_t > $rss_min_delay ) {
$_rss->{last_poll} = $t;
_log rss_fetch_all( $kernel );
}
@@ -738,8 +704,6 @@
# POE handing part
#
-my $SKIPPING = 0; # if skipping, how many we've done
-my $SEND_QUEUE; # cache
my $ping; # ping stats
POE::Component::IRC->new($IRC_ALIAS);
@@ -931,22 +895,32 @@
$res = rss_fetch_all( $_[KERNEL] );
} elsif ($msg =~ m/^rss-clean/) {
$_rss = undef;
+ $dbh->do( qq{ update feeds set last_update = now() - delay } );
$res = "OK, cleaned RSS cache";
+ } elsif ($msg =~ m/^rss-list/) {
+ my $sth = $dbh->prepare(qq{ select url,name,last_update,active from feeds });
+ $sth->execute;
+ while (my @row = $sth->fetchrow_array) {
+ $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) );
+ }
+ $res = '';
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) {
my $sql = {
add => qq{ insert into feeds (url,name) values (?,?) },
# remove => qq{ delete from feeds where url = ? and name = ? },
- start => qq{ update feeds set active = true where url = ? -- ? },
- stop => qq{ update feeds set active = false where url = ? -- ? },
+ start => qq{ update feeds set active = true where url = ? },
+ stop => qq{ update feeds set active = false where url = ? },
};
if (my $q = $sql->{$1} ) {
my $sth = $dbh->prepare( $q );
- warn "## SQL $q ( $2 | $3 )\n";
- eval { $sth->execute( $2, $3 ) };
+ my @data = ( $2 );
+ push @data, $3 if ( $q =~ s/\?//g == 2 );
+ warn "## $1 SQL $q with ",dump( @data ),"\n";
+ eval { $sth->execute( @data ) };
}
- $res ||= "OK, RSS $1 : $2 - $3";
+ $res = "OK, RSS $1 : $2 - $3";
}
if ($res) {
@@ -1214,7 +1188,7 @@
}
$cal->setcontent($dd, qq[
$row->{nr}
$row->{len}
- ]);
+ ]) if $cal;
}
$html .= qq{