歡迎閱讀我最新的一篇文章。
Ruby Script: Delicious to Markdown
因為 tumblr 既有 iPhone app,又有備份程式,所以最近就開始在上面寫點小記錄。
目前打算每週整理一下 delicious 書籤,順手寫篇心得,這樣以後要找資料的時候比較容易些。不過每次要去 delicious.com 翻找、剪下貼上也太笨了,所以就順手寫了個 ruby script 來幫我抓回前一週的書籤,順便排成 markdown 格式。這樣只要書籤的描述有認真寫,大概就可以直接貼上 tumblr 變成一篇文章了。
1 require 'net/https' 2 require "rexml/document" 3 4 username = "user" # your del.icio.us username 5 password = "password" # your del.icio.us password 6 7 resp = href = ""; 8 begin 9 http = Net::HTTP.new("api.del.icio.us", 443) 10 http.use_ssl = true 11 fromdt = (Time.now - 86400*7).strftime("%Y-%m-%d00:00:00Z") 12 http.start do |http| 13 req = Net::HTTP::Get.new("/v1/posts/all?fromdt=" + fromdt, {"User-Agent" => 14 "juretta.com RubyLicious 0.2"}) 15 req.basic_auth(username, password) 16 response = http.request(req) 17 resp = response.body 18 end 19 # XML Document 20 doc = REXML::Document.new(resp) 21 doc.root.elements.each do |elem| 22 print "[" + elem.attributes['description'] + "](" + elem.attributes['href'] + ")\n\n" 23 print elem.attributes['extended'] + "\n\n" 24 end 25 26 rescue SocketError 27 raise "Host " + host + " nicht erreichbar" 28 rescue REXML::ParseException => e 29 print "error parsing XML " + e.to_s 30 end
– 撰寫於 2010/03/01 12:53AM
另外五篇舊文章 (RSS)
- 2010/02/23 My Little Mercenary
- 2010/02/23 Report of the First Season of 2010
- 2009/11/24 Report of the Last Season of 2009
- 2009/09/06 Home Office 2.0
- 2009/07/08 Podcast: 吳東龍 on Design Tokyo

