Version 1 of chatlog reaper

Updated 2007-06-05 11:19:16 by LV

Richard Suchenwirth 2007-06-05 - If you want to see what's going on in the Tcl chatroom, but don't have a chat client available, the following script retrieves the current day's log via http and renders it in HTML to stdout. Redirect it into a file, point your browser to it, enjoy! :^)

 #!/usr/bin/env tclsh
 set usage {
    usage: today.tcl > today.html
    Retrieve today's chat log, format into HTML on stdout
 }
 set base http://tclers.tk/conferences/tcl/

 if {$argv eq "-h"} {puts $usage; exit 1}

 proc main argv {
    package require http
    set date [clock format [clock sec] -format %Y-%m-%d]
    #http::config -proxyhost proxy -proxyport 80
    set token [http::geturl $::base/$date.tcl -headers {Pragma no-cache}]

    puts "<html><head>Tclers' Chat of $date</head><body>"
    eval [html'escape [http::data $token]]
    puts <hr/>[clock format [clock sec]]</body></html>
 }
 interp alias {} html'escape {} string map {< < > > & &}

 #-- All chat entries invoke [m]
 proc m {time who what} {
    if {$who eq "ijchain"} {
        set who [lindex [split $what] 0]
        if {$who eq "***"} {set who ""}
        set what [join [lrange [split $what] 1 end]]
    } 
    set what [string map {\n <br/>} $what] 
    if {$who eq ""} {                      #-- join/leave message
        puts "<br/>* <i>$what</i>"
    } elseif {[string match /me* $what]} { #-- "action"
        puts "<br/><i><b>$who</b> [string range $what 4 end]</i>"
    } else {                               #-- regular message
        puts "<br/><b>$who:</b> $what"
    }
 }
 main $argv

RS update: added Pragma no-cache and \n substitution (for multi-line posts). Notice that the html'escape alias got garbled: the string map makes no sense. Replace with (removing the _):

 < &_lt_; > &_gt_; & &_amp_;

LV 2007 June 05 - well, this seems to provide the heart of a CGI script to display the chat. With some work on generating input to the chat from CGI, we could be back in the chat room ;-) ...


Category example