Purpose: A utility intended to provide the user access to the previous day's [The Tcler's Wiki] chatroom log. ---- # Name: grabchat # Author: [lvirden] # Version: 1 # Purpose: to grab yesterday's tcler's wiki chat room log package require http namespace eval http {} # goal: grab yesterday's tcler's wiki chat log # filename YYYY-MM-DD.txt proc ::http::geturl_followRedirects {url args} { while {1} { set token [eval [list http::geturl $url] $args] switch -glob -- [http::ncode $token] { 30[1237] { ### redirect - see below ### } default { return $token } } upvar #0 $token state array set meta [set ${token}(meta)] if {![info exist meta(Location)]} { return $token } set url $meta(Location) unset meta } } proc ::http::copy { url file {chunk 4096} } { set out [open $file w] set token [::http::geturl $url -channel $out -progress ::http::Progress -blocksize $chunk] close $out # This ends the line started by ::http::Progress puts stderr "" upvar #0 $token state set max 0 foreach {name value} $state(meta) { if {[string length $name] > $max} { set max [string length $name] } if {[regexp -nocase -- ^location$ $name]} { # Handle URL redirects puts stderr "Location:$value" return [copy [string trim $value] $file $chunk] } } incr max foreach {name value} $state(meta) { puts [format "%-*s %s" $max $name: $value] } return $token } proc ::http::Progress {args} { puts -nonewline stderr . ; flush stderr } set chatfile [format "%s.txt" [clock format [clock scan "yesterday"] -format {%Y-%m-%d}]] # Verify that the site is up set token [::http::geturl_followRedirects http://mini.net/tchat/logs/$chatfile -validate 1] if {[regexp -nocase -- {ok} [::http::code $token]]} { ::http::copy http://mini.net/tchat/logs/$chatfile chat.$chatfile } else { puts "$site is dead: [::http::code $token]" } ::http::cleanup $token