--- trunk/bin/irc-logger.pl 2008/03/06 22:57:16 86
+++ trunk/bin/irc-logger.pl 2008/03/07 00:43:45 89
@@ -55,8 +55,6 @@
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;
@@ -77,7 +75,6 @@
use POE qw(Component::IRC Wheel::FollowTail 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;
@@ -104,16 +101,14 @@
'log:s' => \$log_path,
);
-$SIG{__DIE__} = sub {
- confess "fatal error";
-};
+#$SIG{__DIE__} = sub {
+# confess "fatal error";
+#};
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
@@ -282,7 +277,7 @@
-my $sth = $dbh->prepare(qq{
+my $sth_insert_log = $dbh->prepare(qq{
insert into log
(channel, me, nick, message, time)
values (?,?,?,?,?)
@@ -534,7 +529,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;
@@ -603,7 +597,7 @@
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",
" " . $a->{message};
- $sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time});
+ $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time});
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );
}
@@ -655,13 +649,16 @@
# how many messages to send out when feed is seen for the first time?
my $send_rss_msgs = 1;
+ _log "RSS fetch", $args->{url};
+
my $feed = XML::Feed->parse(URI->new( $args->{url} ));
if ( ! $feed ) {
_log("can't fetch RSS ", $args->{url});
return;
}
- my $updates = 0;
+ my ( $total, $updates ) = ( 0, 0 );
for my $entry ($feed->entries) {
+ $total++;
# seen allready?
return if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0;
@@ -679,12 +676,11 @@
# $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++;
- save_message( channel => $CHANNEL, me => 1, nick => $NICK, message => $msg );
- _log('RSS', $msg);
}
}
@@ -693,6 +689,8 @@
$sql .= qq{where id = } . $args->{id};
eval { $dbh->do( $sql ) };
+ _log "RSS got $total items of which $updates new";
+
return $updates;
}
@@ -710,20 +708,19 @@
warn "# ",$sth->rows," active RSS feeds\n";
my $count = 0;
while (my $row = $sth->fetchrow_hashref) {
- warn "+++ fetch RSS feed: ",dump( $row );
$row->{kernel} = $kernel if $kernel;
$count += rss_fetch( $row );
}
return "OK, fetched $count posts from " . $sth->rows . " feeds";
}
-my $rss_last_poll = time();
sub rss_check_updates {
my $kernel = shift;
+ my $last_t = $_rss->{last_poll} || time();
my $t = time();
- if ( $rss_last_poll - $t > $rss_min_delay ) {
- $rss_last_poll = $t;
+ if ( $last_t - $t > $rss_min_delay ) {
+ $_rss->{last_poll} = $t;
_log rss_fetch_all( $kernel );
}
}
@@ -748,9 +745,6 @@
},
irc_255 => sub { # server is done blabbing
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL);
- $_[KERNEL]->post($IRC_ALIAS => join => '#logger');
- $_[KERNEL]->yield("heartbeat"); # start heartbeat
- $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS;
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
},
irc_public => sub {
@@ -993,67 +987,6 @@
"";
0; # false for signals
},
- my_add => sub {
- my $trailing = $_[ARG0];
- my $session = $_[SESSION];
- POE::Session->create
- (inline_states =>
- {_start => sub {
- $_[HEAP]->{wheel} =
- POE::Wheel::FollowTail->new
- (
- Filename => $FOLLOWS{$trailing},
- InputEvent => 'got_line',
- );
- warn "+++ following $trailing at $FOLLOWS{$trailing}\n";
- },
- got_line => sub {
- warn "+++ $trailing : $_[ARG0]\n";
- $_[KERNEL]->post($session => my_tailed => time, $trailing, $_[ARG0]);
- },
- },
- );
-
- },
- my_tailed => sub {
- my ($time, $file, $line) = @_[ARG0..ARG2];
- ## $time will be undef on a probe, or a time value if a real line
-
- ## PoCo::IRC has throttling built in, but no external visibility
- ## so this is reaching "under the hood"
- $SEND_QUEUE ||=
- $_[KERNEL]->alias_resolve($IRC_ALIAS)->get_heap->{send_queue};
-
- ## handle "no need to keep skipping" transition
- if ($SKIPPING and @$SEND_QUEUE < 1) {
- $_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL =>
- "[discarded $SKIPPING messages]");
- $SKIPPING = 0;
- }
-
- ## handle potential message display
- if ($time) {
- if ($SKIPPING or @$SEND_QUEUE > 3) { # 3 msgs per 10 seconds
- $SKIPPING++;
- } else {
- my @time = localtime $time;
- $_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL =>
- sprintf "%02d:%02d:%02d: %s: %s",
- ($time[2] + 11) % 12 + 1, $time[1], $time[0],
- $file, $line);
- }
- }
-
- ## handle re-probe/flush if skipping
- if ($SKIPPING) {
- $_[KERNEL]->delay($_[STATE] => 0.5); # $time will be undef
- }
-
- },
- my_heartbeat => sub {
- $_[KERNEL]->yield(my_tailed => time, "heartbeat", "beep");
- $_[KERNEL]->delay($_[STATE] => 10);
- }
},
);
@@ -1275,7 +1208,7 @@
}
$cal->setcontent($dd, qq[
$row->{nr}
$row->{len}
- ]);
+ ]) if $cal;
}
$html .= qq{