此版本尚未支援 影片代碼 功能

原始碼如下:
require 'rubygems'
require 'mechanize'

class HEMiDEMi
  def initialize(username="", password="")
    agent = WWW::Mechanize.new{}
    f = agent.get("http://www.hemidemi.com/member/signin_form").forms[1]
    f["member[username]"], f["member[password]"] = username, password
    f.submit
    @agent = agent
    @base_url = "http://www.hemidemi.com"
    @new_path = "/user_bookmark/new"
  end
 
  def run(file)
    File.open(file) do |f|
      f.readlines.each do |frl|
        next if frl[0].chr == "#"
        title, url, quotes, description, t_s, g_s = frl.split(/\t/)
        self.add({
          "title" => title,
          "url" => url,
          "quotes" => quotes,
          "description" => description,
          "tag_string" => t_s,
          "group_string" => g_s
        })
      end
    end
  end
 
  def add(qs)
    f = @agent.get(@base_url+@new_path).forms[1]
    qs.each do |k, v|
      puts "Add: #{k} as #{v}"
      f["user_bookmark[#{k}]"] = v
    end
    f.fields.each do |x| puts x.name + " => " + x.value end
    f.submit
  end

end
puts "請輸入HEMiDEMi使用者帳號跟密碼(用空格分開):"
ud = gets.chomp.split(/ /)
hemidemi = HEMiDEMi.new(ud[0], ud[1])
puts "請輸入檔案位置,不輸入則預設值為當前目錄下的bms.txt:"
path = gets.chomp
path == "" ? hemidemi.run("bms.txt") : hemidemi.run(path)


另外,bms.txt檔案內容是:

# 欄位說明:
#   title\turl\tquotes\tdescription\ttag_string\tgroup_string
#   標題<tab>網址<tab>引述<tab>說明<tab>標籤<tab>群組
#   <tab>:按一次Tab鍵
# 底下是範例:
HEMiDEMi    http://www.hemidemi.com        HEMiDEMi共享書籤    hemidemi    test ruby_and_ror

說明:

請先建立好bms.txt或者其他檔案名稱的純文字檔
欄位寫的很清楚,就是:標題<tab>網址<tab>引述<tab>說明<tab>標籤<tab>群組
請記得一定要用tab來分隔,建議用Windows內建的記事本來編寫
如果想要空掉某些欄位,則該欄位不填直接按下tab鍵即可,看範例就可以知道 (範例沒有寫上引述)

程式授權:MIT
程式所需套件:rubygems、mechanize跟mechanize之所需套件
mechanize安裝方式:
  請先確定有rubygems,如果沒有請到RubyForge下載安裝
  打開命令提示字元或者終端機,輸入:
    gem i mechanize -y
  如果有要你選版本的話,Windows使用者請選擇(mswin32)版本,而其他作業系統請選(ruby)版本
程式原始碼下載:
Windows (Big5)
Linux (UTF-8)
arrow
arrow
    全站熱搜

    hechian 發表在 痞客邦 留言(0) 人氣()