To run the script, either do a...
tclsh jaikuarchive.tcl marks
... or for the more pure way, opt for:
chmod +x jaikuarchive.tcl
./jaikuarchive.tcl marks
| #!/usr/bin/tclsh | |
| package require http | |
| package require json | |
| proc get_jaiku_dict {username {offset ""}} { | |
| if { $offset ne "" } { | |
| set url "http://${username}.jaiku.com/json?offset=${offset}" | |
| } else { | |
| set url "http://${username}.jaiku.com/json" | |
| } | |
| set tok [http::geturl $url] | |
| set json [http::data $tok] | |
| set ret [json::json2dict $json] | |
| return $ret | |
| } | |
| proc index_jaiku_archive {url} { | |
| regexp {^[^\#]+} $url clean_url | |
| puts "Indexing $clean_url" | |
| set archive_url [string map [list "jaiku.com" "jaikuarchive.com"] $clean_url] | |
| http::geturl $archive_url | |
| after 1000 | |
| } | |
| proc parse_timestamp {timestamp} { | |
| regsub -all {(....)-(..)-(..)T(..)-(..)-(..)Z} $timestamp {\1-\2-\3 \4:\5:\6} timestamp | |
| return [clock scan $timestamp] | |
| } | |
| proc loop_jaiku {username} { | |
| set offset "" | |
| while { 1 } { | |
| puts "Getting data with offset = $offset" | |
| set data [get_jaiku_dict $username $offset] | |
| set stream [dict get $data stream] | |
| if { [llength $stream] } { | |
| foreach item $stream { | |
| set url [dict get $item url] | |
| index_jaiku_archive $url | |
| set created_at [dict get $item created_at] | |
| } | |
| set offset [expr [parse_timestamp $created_at] - 1] | |
| } else { | |
| puts "Done" | |
| return | |
| } | |
| } | |
| } | |
| set username [lindex $argv 0] | |
| loop_jaiku $username |
To run the script, either do a...
tclsh jaikuarchive.tcl marks
... or for the more pure way, opt for:
chmod +x jaikuarchive.tcl
./jaikuarchive.tcl marks