ã¨ããããã§publish::delicious
æ¨æ¥ã®del.icio.usにPOSTするスクリプトãPRaggerã®ãã©ã°ã¤ã³ã«ãã¾ãããè¿ããã¡ã«ã¡ããã¨ã³ã¡ã³ããã¤ãã¾ãã
ã¨ã©ã¼å¦çããªããã¤ãã¤ãããã
## Publish::delicious - to post feed items to del.icio.us-- emergent ## ## - module: Publish::delicious ## config: ## username: your_username ## password: your_password ## opt_tag: pragger ## no_comment: 1 ## require 'rubygems' require 'mechanize' require 'uri' require 'kconv' class Delicious def initialize username, password, proxy=nil @username = username @password = password @agent = WWW::Mechanize.new @agent.basic_auth(@username, @password) if proxy && proxy.is_a?(Hash) && proxy['proxy_addr'] && proxy['proxy_port'] @agent.set_proxy(proxy['proxy_addr'], proxy['proxy_port'], proxy['proxy_user'], proxy['proxy_pass']) end end def post url, desc, option=nil params = {} post_url = 'https://api.del.icio.us/v1/posts/add?' params[:url] = url params[:description] = desc if option params[:extended] = option["summary"] if option["summary"] params[:dt] = option["datetime"] if option["datetime"] params[:tags] = option["tags"] if option["tags"] params[:replace] = 'no' if option["no_replace"] params[:shared] = 'no' if option["private"] end req_param = [] params.map do |k,v| req_param << k.to_s.toutf8 + '=' + v.toutf8 if (v.length > 0) end result = @agent.get(URI.encode(post_url + req_param.join('&'))) puts URI.encode(post_url + req_param.join('&')) if result.body =~ /code="done"/ return true end false end end def get_tags entry entry.dc_subjects.map do |s| s.content end.join(' ') rescue '' end def delicious config, data sleeptime = 3 if config['sleep'] sleeptime = config['sleep'].to_i end data.each {|entry| print 'posting ' + entry.title + ': ' tags = get_tags entry if config['opt_tag'] tags = [tags, config['opt_tag']].select{|t| t.length > 0}.join(' ') end summary = config['no_comment'].to_i > 0 ? '' : entry.description begin agent = Delicious.new(config['username'], config['password']) res = agent.post(entry.link, entry.title, 'tags' => tags, 'summary' => summary) if res then puts 'done' else puts 'failed' end rescue puts 'exception' #raise end sleep sleeptime } data end
使ãæ¹
publish::hatena_bookmarkã¨æ®ã©åãã§ãããsleepæéã¯ããã©ã«ãã§3ç§ã«ãã¦ããã¾ãã
no_commentãªãã·ã§ã³ãä»ããã¨ãã³ã¡ã³ãã渡ãã¾ãããããã¯ãä¾ãã°ããã°ã®ãã£ã¼ããåã£ã¦ãã¦æ稿ããå ´åãdescriptionã«é·ã
ã¨æç« ãæ¸ãã¦ããã¨æ稿ã«å¤±æããããã§ãããã®è¾ºã®æåæ°ã®å¶éã¨ããå³å¯ã«ãã§ãã¯ããæ¹ãããã§ãããTODOãã£ã¨ã
- module: RSS::load config: url: http://b.hatena.ne.jp/hotentry?mode=rss - module: Publish::delicious config: username: username password: password opt_tag: "imported" sleep: 4 no_comment: 1
TODO
- proxyè¨å®ã§ããããã«ãã¦ãããªããYAMLã§æå®ã§ããããã«ããã®å¿ãã¦ãorz
ã³ã¡ã³ãæ¸ã
追è¨
post_url = 'https://api.del.icio.us/v1/posts/add?'
ã®é¨åã
post_url = 'https://secure.bluedot.us/v1/posts/add?'
ã«å¤ããã¨BlueDotã«ãæ稿ã§ãã¾ãã
å¤æ´å±¥æ´
- 2007/05/20 表è¨ãrev.74ã®ä»æ§ã«åããã