[[FrontPage]]
+はてなブックマークのfeedを取得
+Googleにログインして
+一つずつPOST

はてなブックマークのFeedの取得は、以前作った[[hbmark]]で全取得して、保存。 あとは以下の書き捨てスクリプトを回して完了。

 set dumpfile ./all.xml
 set mail my@loginmail
 set pass mypassword
 set ua "Mozilla/5.0 (Windows; U; Windows NT 5.0; ja; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"
 set google "http://www.google.com"
 
 package require http
 package require tls
 package require cookiejar
 http::register https 443 ::tls::socket
 http::config -useragent $ua -urlencoding utf-8
 cookiejar::configure -debug 0 -info 0
 
 #-------------------------------------------------------------
 # Google 
 #-------------------------------------------------------------
 proc login {mail pass} {
     set posturl https://www.google.com/accounts/LoginAuth
 
     set token [http::geturl $posturl \
         -query [http::formatQuery \
             Email    $mail\
             PersistentCookie yes\
             Passwd    $pass\
             null "ログイン"]]
     upvar #0 $token state
     foreach {k v} $state(meta) {
         if {$k eq "Location"} {
             set next $v
             break;
         }
     }
     http::cleanup $token
 
     set token [http::geturl $next]
     upvar #0 $token state
     foreach {k v} $state(meta) {
         if {$k eq "Location"} {
             set next $v
             break;
         }
     }
     http::cleanup $token
 
     set token [http::geturl $next]
     http::cleanup $token
 
 }
 
 proc move {url} {
     set url $::google$url
     set token [http::geturl $url]
     upvar #0 $token state
     foreach {k v} $state(meta) {
         if {$k eq "Location"} {
             set next $v
             break;
         }
     }
     http::cleanup $token
     return $next
 }
 
 proc addBookmark {bkmk title tags comment} {
     set url [move "/bookmarks/mark?op=add"]
     set token [http::geturl $::google$url]
     set html [http::data $token]
 
     set q {hidden name=sig value="(.*?)"}
     set siglist [regexp -linestop -inline -all -- $q $html]
     if {[llength $siglist] == 0} {error "failed to get sig list"}
     set sig [lindex $siglist 1]
     
     set q {name="add_bkmk_form" action="(.*?)"}
     set postlist [regexp -linestop -inline -all -- $q $html]
     set posturl [lindex $postlist 1]
     http::cleanup $token
     
     set token [http::geturl $::google$posturl \
         -query [http::formatQuery \
             title        $title \
             bkmk        $bkmk \
             labels        [join $tags ,] \
             annotation    $comment \
             sig            $sig \
             prev        /lookup \
             q            is:bookmarked \
             btnA        ブックマークを追加 \
             btnC        キャンセル]]
 }
 #-------------------------------------------------------------
 # Do 
 #-------------------------------------------------------------
 source c:/doc/tcl/mailme.tcl
 login $mail $pass
 package require tdom
 
 set fp [open $dumpfile r]
 fconfigure $fp -encoding utf-8
 set xml [read $fp]
 close $fp
 set doc [dom parse $xml]
 
 set elist [list]
 foreach enode [$doc getElementsByTagName entry] {
     set elist [concat $enode $elist]
 }
 
 foreach enode $elist {
     set link ""
     foreach lnode [$enode getElementsByTagName link] {
         if {[$lnode getAttribute rel] eq "related"} {
             set link [string trim [$lnode getAttribute href]]
             break;
         }
     }
     if {$link eq ""} {
         puts [$enode asXML]
         continue
     }
     set tags [list]
     foreach tnode [$enode getElementsByTagName dc:subject] {
         lappend tags [string trim [$tnode asText]]
     }
     set title [string trim [[$enode getElementsByTagName title] asText]]
     set sum   [string trim [[$enode getElementsByTagName summary] asText]]
     puts $title
     if {[catch {addBookmark $link $title $tags $sum}]} {
         puts [$enode asXML]
     }
     after 10000
 }
 
 
 #完了したら携帯電話にメールを送る
 EMailSend "H2G Complete!!" ""

----
[[Categoryはてな]] [[CategoryGoogle]] [[CategoryTclTk]]


HTML convert time: 0.008 sec.