Hatena::Grouptumblr

TETRiS THE ABSOLUTE THE GRAND MASTER2

2008-08-27

v4

21:11

v4対応

require "rubygems"
require "mechanize"

class Tumblr
  def initialize email, pass
    @email = email
    @pass  = pass
    @agent = WWW::Mechanize.new
  end
  
  def login
    login = @agent.get("http://www.tumblr.com/login")
    login.forms[0]["email"]    = @email
    login.forms[0]["password"] = @pass
    login.forms[0].submit
    logined?
  end
  
  def logined?
    page = @agent.get "http://www.tumblr.com/dashboard"
    a = (page/'//div/div/div/a[5]')[0]
    a.innerHTML == "Log out"
  end
  
  def reblog url
    unless logined? then
      login
    end
    begin
      post = @agent.get url
      iframe = (post/'iframe[@id="tumblr_controls"]')[0]["src"]
      #iframe = "http://www.tumblr.com/dashboard/iframe?src=" + url
      reblog = @agent.get(iframe).links[0].click
      reblog.forms[0].submit
    rescue
      puts "reblog failed"
    end
  end
  
  def follow url
    unless logined? then
      login
    end
    begin
      page = @agent.get url
      iframe = (page/'iframe[@id="tumblr_controls"]')[0]["src"]
      form = @agent.get(iframe).forms[0]
      unless form.action == "/remove_friend"
        form.submit
        puts "follow #{url}"
      end
    rescue
      puts "failed #{url}"
    end
  end
end

JanisaJanisa2012/01/10 01:00In awe of that aneswr! Really cool!

dkdcelvrfgedkdcelvrfge2012/01/10 17:11qZjA2U <a href="http://vgxgyurzxnyo.com/">vgxgyurzxnyo</a>

jwuexkebbjwuexkebb2012/01/11 00:48l7MeSd , [url=http://zqzppanjmuij.com/]zqzppanjmuij[/url], [link=http://idnglscsujex.com/]idnglscsujex[/link], http://vkkvocpirard.com/

2008-07-12

Reblog LDR Pin

03:44

LDRpin立てて、一気にreblog。連投すると怒られるのでsleepを置いてる。

問題は、他人のFeedはLDRで巡回してるくせに、自分のpostは最新20件までしかLDRに読み込まれない事。

tumblr.rb

require "rubygems"
require "mechanize"

class Tumblr
  def initialize email, pass
    @email = email
    @pass  = pass
    @agent = WWW::Mechanize.new
  end
  
  def login
    login = @agent.get("http://www.tumblr.com/login")
    login.forms[0]["email"]    = @email
    login.forms[0]["password"] = @pass
    login.forms[0].submit
    logined?
  end
  
  def logined?
    page = @agent.get "http://www.tumblr.com/"
    a = (page/'//ul/li[3]/a')[0]
    a.innerHTML == "Dashboard"
  end
  
  def reblog url
    unless logined? then
      login
    end
    begin
      post = @agent.get url
      iframe = (post/'iframe[@id="tumblr_controls"]')[0]["src"]
      #iframe = "http://www.tumblr.com/dashboard/iframe?src=" + url
      reblog = @agent.get(iframe).links[0].click
      reblog.forms[0].submit
    rescue
      puts "reblog failed"
    end
  end
end

reblog_ldrpin.rb

#!/usr/bin/ruby
require "rubygems"
require "mechanize"
require "json"
require "tumblr"

agent = WWW::Mechanize.new

login = agent.get("http://reader.livedoor.com/reader")

login.forms[0]["livedoor_id"] = "xxxxxxxx"
login.forms[0]["password"] = "xxxxxxxx"
login.forms[0].submit

data = agent.post("http://reader.livedoor.com/api/pin/all").body

links = JSON.parse(data)

tumblr = Tumblr.new "xxxx@xxxx.com", "xxxxxx"

links.each do |link|
  puts "reblog " + link["link"]
  tumblr.reblog link["link"]
  sleep 30
end

なんでkconvなんてrequireしてるんだろ?いらないから消した。

あと、gemruby-tumblrってのがあるね。API叩くみたい。