Skip to content

Instantly share code, notes, and snippets.

@steffentchr
Created November 28, 2011 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steffentchr/1401409 to your computer and use it in GitHub Desktop.
Save steffentchr/1401409 to your computer and use it in GitHub Desktop.
A script to loop through your Jaiku history and index+preserve it through Jaiku Archive (http://www.jaikuarchive.com). Usage: ./jaikuarchive.tcl <username>
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment