Updated 2013-08-07 21:25:03 by pooryorick

Summary  edit

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! :^)

Lars H 2008-07-28: A safer version of this script can be found in the empty interpreter page.''
#!/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 {< &lt; > &gt; & &amp;}
set lasttime 00:00

#-- All chat entries invoke [m]
proc m {time who what} {
    set tm [string range $time 9 13]
    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
        if {$tm ne $::lasttime} {
            set who "$tm $who"
            set ::lasttime $tm
        }
        puts "<br/><b>$who:</b> $what"
    }
}
main $argv

RS update: added Pragma no-cache and \n substitution (for multi-line posts).

A little test:
string map {< &lt; > &gt; & &amp;}

LV 2007-06-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 ;-) ...

RS: Yes indeed. If Tkabber could take chat posts from a HTTP POST, that would be even easier - the above script would at the end produce an entry widget and a Post button which would do the right thing...

escargo: Could this be combined with tkhtml to avoid the need for a separate browser?

LV: well, with some work it could. Right now, it outputs the html to stdout. Unless you want to do something funky like redirect that output to a file, then somehow reread it over and over again, something has to be done to a) return the output, and b) handle the refresh, etc. And then, some code has to be written do handle links, display the smilies, etc. All doable. Just will take more time than I have to play today :-( ...

escargo: I wasn't trying to imply handling refreshes or following links; just handling the markup and avoiding having to write the file. I don't think smiley processing is required either. (It's kind of like using tkhtml as a help file viewer; I wasn't expecting anything highly dynamic.)

RS: Added time display (minutes only, and only when changed).

TR: Interesting. What about adding this to www.tck.tk at an appropriate place (or even the front page) so we have something like a link for 'what is going on in the chat/community right now?' that would show the current status of discussion. That would give people a sneak peek into the chat without logging in.