Version 5 of Daily Dilbert

Updated 2005-08-02 06:20:49

Just for fun: Get your daily Dilbert comic and display it. If you provide a directory name as argument, it'll be saved to dirname/dilbertyyyymmdd.gif where yyyymmdd is todays date.


 package require Tk
 package require http
 package require base64

 set um [http::geturl http://www.dilbert.com/]
 set b [split [http::data $um] "\n"]
 set ln [lsearch -inline -glob $b "*ALT=?Today's Dilbert Comic*"]
 regexp {^.*IMG SRC=\"([^"]+)\".*$} $ln --> picurl
 http::cleanup $um
 set um [http::geturl http://www.unitedmedia.com$picurl]
 if {$argc && [file isdirectory [lindex $argv 0]]} {
   set today [clock format [clock seconds] -format "dilbert%Y%m%d.gif"]
   set fd [open $today w]
   fconfigure $fd -translation binary -encoding binary
   puts $fd [http::data $um]
   close $fd
 }
 set pic [base64::encode [http::data $um]]
 http::cleanup $um
 image create photo dilbert -data $pic
 label .l -image dilbert
 pack .l

Michael Jacobson: Also see Comic Server for some code to get a bunch of comic strips from uComics. Or you can check out (on windows only ~ sorry) in a TclKit application that servers the comics and display them in a embededd MSIE frame using optcl. Get the application here ... http://mywebpages.comcast.net/jakeforce/COMon!ics.kit (96kb). (I use this code in NewzPoint)


02. Aug. 2005: The Text for the daily gilbert comic changed. Replace the lsearch line with the following:

 set ln [lsearch -inline -glob $b "*ALT=?Today's Comic*"]