From: timriker Date: Thu, 7 Nov 2002 06:18:16 +0000 (+0000) Subject: html from logs X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0d86e641dab2ccd3e76e34d26ef86e6dc9360983;p=infobot.git html from logs git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@606 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/blootbot/scripts/irclog2html.pl b/blootbot/scripts/irclog2html.pl new file mode 100755 index 0000000..6714ffd --- /dev/null +++ b/blootbot/scripts/irclog2html.pl @@ -0,0 +1,327 @@ +#!/usr/bin/perl + +# irclog2html.pl Version 1.5 - 11th May 2000 +# Copyright (C) 2000, Jeffrey W. Waugh + +# Author: +# Jeff Waugh + +# Contributors: +# Rick Welykochy +# Alexander Else + +# Released under the terms of the GNU GPL +# http://www.gnu.org/copyleft/gpl.html + +# Modified by Tim Riker +# to work with infobot logs +# then modified again for blootbot + +# Usage: irclog2html < logfile + +# irclog2html will write out a colourised irc log, appending a .html +# extension to the output file. + + +#################################################################################### +# Perl Configuration + +use strict; +$^W = 1; #RW# turn on warnings +use POSIX qw(strftime); + + +#################################################################################### +# Preferences + +# Comment out the "table" assignment to use the plain version + +#my $STYLE = "tt"; +#my $STYLE = "simplett"; +#my $STYLE = "table"; +my $STYLE = "simpletable"; + +my $colour_left = "#000099"; # nick leaving channel +my $colour_joined = "#009900"; # nick joining channel +my $colour_server = "#009900"; # server message (***) +my $colour_nickchange = "#009900"; # nick change +my $colour_action = "#CC00CC"; # nick action (/me waves) + +my %prefs_colour_nick = ( + "jdub" => "#993333", + "cantanker" => "#006600", + "chuckd" => "#339999", +); + + +#################################################################################### +# Utility Functions + +sub header { + my ($channel, $date) = @_; + my $return = ''; + + $return .= qq{ + + + irclog2html for $channel on $date + + + + + +

irclog2html for $channel on $date

+}; + + if ($STYLE =~ /table/) { + $return .= "\n"; + } + return $return; +} + +sub footer { + my $return = ''; + if ($STYLE =~ /table/) { + $return .= "
\n"; + } + + $return .= qq{ +
Generated by irclog2html.pl by +Jeff Waugh - find it at +freshmeat.net! +Modified by Tim Riker to work with +blootbot logs, split per channel, etc. +
+}; + return $return; +} + +my $lastdate = ''; + +sub add_footers { + my $filename; + + return if not $lastdate; + + my @files=`ls $lastdate.html */$lastdate.html`; + foreach $filename (@files) { + chomp $filename; + if (!open(OUTPUT, ">>$filename")) { + die "Cannot open $filename for writing!\n\n"; + } + print OUTPUT footer(); + close OUTPUT; + } +} + +sub output_line { + my ($date, $time, $channel, $lineout) = @_; + + add_footers() if $lastdate ne $date; + + $lastdate = $date; + my $filename = ""; + $filename .= "$channel/" if $channel; + $filename .= "$date.html"; + + mkdir($channel,oct('755')) if ($channel && ! -d $channel); + if (!open(OUTPUT, ">>$filename")) { + die "Cannot open $filename for writing!\n\n"; + } + # Begin output # + print OUTPUT header($channel, $date) if -z $filename; + + print OUTPUT $lineout; + + close OUTPUT; +} + +sub output_timenicktext { + my ($date, $time, $channel, $nick, $text, $htmlcolour) = @_; + my $lineout = ''; + + if ($STYLE eq "table") { + $lineout .= ""; + $lineout .= "$time" if $time; + $lineout .= "$nick"; + $lineout .= "$text<\/font>\n"; + } + elsif ($STYLE eq "simpletable") { + $lineout .= ""; + $lineout .= "$time" if $time; + $lineout .= "$nick"; + $lineout .= "$text\n"; + } + elsif ($STYLE eq "simplett") { + $lineout .= "$time " if $time; + $lineout .= "<\;$nick>\; $text
\n"; + } + else { + $lineout .= "$time " if $time; + $lineout .= "<\;$nick>\; $text<\/font>
\n"; + } + output_line($date, $time,$channel,$lineout); +} + +sub output_timeservermsg { + my ($date, $time, $line) = @_; + my $lineout = ''; + + if ($STYLE =~ /table/) { + $lineout .= ""; + $lineout .= "$time" if $time; + $lineout .= "$line\n"; + } + else { + $lineout .= "$time " if $time; + $lineout .= "$line
\n"; + } + output_line($date, $time,'',$lineout); +} + +sub html_rgb +{ + my ($i,$ncolours) = @_; + $ncolours = 1 if $ncolours == 0; + + my $rgbmax = 125; # tune these two for the outmost ranges of colour depth + my $rgbmin = 240; + + my $a = 0.95; # tune these for the starting and ending concentrations of R,G,B + my $b = 0.5; + + my $rgb = [ [$a,$b,$b], [$b,$a,$b], [$b,$b,$a], [$a,$a,$b], [$a,$b,$a], [$b,$a,$a] ]; + my $n = $i % @$rgb; + my $m = $rgbmin + ($rgbmax - $rgbmin) * ($ncolours - $i) / $ncolours; + + my $r = $rgb->[$n][0] * $m; + my $g = $rgb->[$n][1] * $m; + my $b = $rgb->[$n][2] * $m; + sprintf("#%02x%02x%02x",$r,$g,$b); +} + +#################################################################################### +# Main + +sub main { + my ($date) = @_; + my $files; + + my $line; + my $time; + my $lastdate = ""; + my $nick; + my $channel; + my $text; + + my $htmlcolour; + my $nickcount = 0; + my $NICKMAX = 30; + + my %colour_nick = %prefs_colour_nick; + + while ($line = ) { + + chomp $line; + + if (!$line eq "") { + + # parse out the time + if ($line =~ s/^([0-9:\.]*) (.*)$/\2/) { + $time = $1; + } else { + $time = ""; + } + + # Replace ampersands, pointies, control characters # + $line =~ s/&/&\;/g; + $line =~ s//>\;/g; + $line =~ s/\e\[[0-1]*m//g; + $line =~ s/[\x00-\x1f]+//g; + + # Replace possible URLs with links # + $line =~ s/((http|https|ftp|gopher|news):\/\/\S*)/$1<\/a>/g; + + # Colourise the comments + if ($line =~ /^<\;[^\/]*?\/\#.*?>\; .*$/) { + # Split $nick, $channel and $line + $nick = $line; + $nick =~ s/^<\;([^\/]*?)\/\#.*?>\; .*$/$1/; + $channel = $line; + $channel =~ s/^<\;[^\/]*?\/\#(.*?)>\; .*$/$1/; + + # $nick =~ tr/[A-Z]/[a-z]/; + # <======= move this into another function when getting nick colour + + $text = $line; + $text =~ s/^<\;.*?>\; (.*)$/$1/; + $text =~ s/ / \; \;/g; + + $htmlcolour = $colour_nick{$nick}; + if (!defined($htmlcolour)) { + # new nick + $nickcount++; + + # if we've exceeded our estimate of the number of nicks, double it + $NICKMAX *= 2 if $nickcount >= $NICKMAX; + + $htmlcolour = $colour_nick{$nick} = html_rgb($nickcount, $NICKMAX); + } + output_timenicktext($date, $time, $channel, $nick, $text, $htmlcolour); + } + + elsif ($line =~ /^>\;>\;>\; /) { + $line =~ s/^>\;>\;>\; /\*\*\* /; + + # Process changed nick results, and remember colours accordingly # + if ($line =~ /\*\*\* (.*?) are|is now known as (.*)/) { + my $nick_old; + my $nick_new; + + $nick_old = $line; + $nick_old =~ s/\*\*\* (.*?) (are|is) now known as .*/$1/; + + $nick_new = $line; + $nick_new =~ s/\*\*\* .*? (are|is) now known as (.*)/$2/; + + $colour_nick{$nick_new} = $colour_nick{$nick_old}; + $colour_nick{$nick_old} = undef; + + $line =~ s/(\*\*\* .*)/$1<\/font>/ + } + + # Colourise joined/left/server messages # + elsif ($line =~ /\*\*\* .*left|quit/) { + $line =~ s/(\*\*\* .*)/$1<\/font>/; + } + elsif ($line =~ /\*\*\* .*joined/) { + $line =~ s/(\*\*\* .*)/$1<\/font>/; + } + elsif ($line =~ /\*\*\* /) { + $line =~ s/(\*\*\* .*)$/$1<\/font>/; + } + + # Colourise the /me's # + elsif ($line =~ /^\* .*$/) { + $line =~ s/^(\*.*)$/$1<\/font>/; + } + + output_timeservermsg($date, $time, $line); + } + } + } + + add_footers(); + + return 0; +} + +if (!scalar @ARGV) { + print "Usage: irclog2html.pl < logfile\n"; + print "Example: bzcat log/blootbot.log-20021104.bz2 | irclog2html.pl 20021104\n"; + exit 0; +} +my $date = shift; +exit &main($date); +# vim: ts=2