Difference between revisions of "User:Dr Scofield/logtransform"
Jump to navigation
Jump to search
Dr Scofield (talk | contribs) (+ sllog2wiki tool) |
Dr Scofield (talk | contribs) (~ bug fix) |
||
(One intermediate revision by the same user not shown) | |||
Line 40: | Line 40: | ||
while (<>) { | while (<>) { | ||
if (m/( # $1: captures whole lead | if (m/( # $1: captures whole lead | ||
(\ | \[(?:\d{4}\/\d{2}\/\d{2}\s+)?(\d{1,2}:\d{2})\]\s+? # $2: captures optional timestamp [13:00] | ||
((?:you|\S+\s+[^\s:]+)) # $3: captures Firstname Lastname | ((?:you|\S+\s+[^\s:]+)) # $3: captures Firstname Lastname | ||
([\s:]) # $4: captures (:| ) | ([\s:]) # $4: captures (:| ) | ||
Line 46: | Line 46: | ||
\s* # gobble up white space | \s* # gobble up white space | ||
(.*) # $5 captures actual text | (.*) # $5 captures actual text | ||
/ | /xi) { | ||
my $timestamp = $2 | my $timestamp = $2 ? '[' . $2 . ']' : " "; | ||
my $who = $3; | my $who = $3; | ||
my $sep = $4; | my $sep = $4; | ||
my $text = $5; | my $text = $5; | ||
if ( | if ($who =~ m/you/i) { | ||
$who = $you; | $who = $you; | ||
} | } | ||
Line 96: | Line 96: | ||
printf STDOUT "| $timestamp\n"; | printf STDOUT "| $timestamp\n"; | ||
if ($sep =~ /:/) { | if ($sep =~ /:/) { | ||
printf STDOUT "| [[User:$who|$who]]:\n"; | printf STDOUT "| style=\"white-space:nowrap;\"|[[User:$who|$who]]:\n"; | ||
printf STDOUT "| style=\"white-space:normal;\"|" . $text . "\n"; | printf STDOUT "| style=\"white-space:normal;\"|" . $text . "\n"; | ||
} else { | } else { | ||
Line 122: | Line 122: | ||
} | } | ||
} | } | ||
</pre> | </pre> |
Latest revision as of 04:32, 9 January 2008
SLlog2wiki
below is a small script that transforms SL chat logs into wiki tables for posting onto this wiki. you need to invoke it with the full name of the note taker; for example, assuming i was the note taker:
sllog2wiki --taker="Dr Scofield" < raw-log > wiki-log
you can also create a config file for this little script and place your fullname in there, like this:
# $HOME/.sllog2wikirc file taker = Dr Scofield
and here's the script, copy & paste into a perl script file:
#!/usr/bin/perl # Placed into the public domain by IBM Research. use strict; use English; use Getopt::Long; sub eject_header ( ); sub eject_line ( $$$$ ); sub eject_footer ( ); sub load_cfg ( ); my $you = undef; load_cfg; GetOptions("taker=s" => \$you); if (!$you) { printf STDERR "you need to specify who you are via --taker=\"First Last\"\n"; exit 1; } eject_header; while (<>) { if (m/( # $1: captures whole lead \[(?:\d{4}\/\d{2}\/\d{2}\s+)?(\d{1,2}:\d{2})\]\s+? # $2: captures optional timestamp [13:00] ((?:you|\S+\s+[^\s:]+)) # $3: captures Firstname Lastname ([\s:]) # $4: captures (:| ) ) \s* # gobble up white space (.*) # $5 captures actual text /xi) { my $timestamp = $2 ? '[' . $2 . ']' : " "; my $who = $3; my $sep = $4; my $text = $5; if ($who =~ m/you/i) { $who = $you; } eject_line $timestamp, $who, $sep, $text; next; } print "??? ", $_; } eject_footer; exit 0; sub eject_header() { printf STDOUT "{|\n"; } my $last_who = undef; my $cidx = 0; sub eject_line($$$$) { my $timestamp = shift; my $who = shift; my $sep = shift; my $text = shift; my $bg = ""; if (defined $last_who and $last_who ne $who) { $cidx = ($cidx + 1) % 2; } $last_who = $who; if (0 == $cidx) { $bg="background-color:#FFFFFF;"; } else { $bg="background-color:#F0F0F0;"; } $text =~ s/%/%%/g; $who =~ s/\s+/ /g; printf STDOUT "|- style=\"vertical-align:top;$bg\"\n"; printf STDOUT "| $timestamp\n"; if ($sep =~ /:/) { printf STDOUT "| style=\"white-space:nowrap;\"|[[User:$who|$who]]:\n"; printf STDOUT "| style=\"white-space:normal;\"|" . $text . "\n"; } else { printf STDOUT "| colspan=\"2\"|''$who " . $text . "''\n"; } } sub eject_footer() { printf STDOUT "|}"; } sub load_cfg() { my $cfg = $ENV{'HOME'} . "/.sllog2wikirc"; return unless -e $cfg and -r $cfg; open CFG, "<$cfg" or die "cannot open config file $cfg ($!)"; my @cfg = <CFG>; close CFG; foreach my $l (@cfg) { next unless $l =~ m/^\s*([^=]+?)\s*=\s*(.+)\s*$/; if (! grep(/$1=/, @ARGV)) { push @ARGV, '--' . $1 . '=' . $2; } } }