Skip to content

Instantly share code, notes, and snippets.

@oquno
Created September 26, 2009 17:58
Show Gist options
  • Save oquno/194341 to your computer and use it in GitHub Desktop.
Save oquno/194341 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
require 'nokogiri'
require 'open-uri'
require 'kconv'
# original source -> http://d.hatena.ne.jp/gigi-net/20090919/1253370152
mixi_username ='MAIL' #mixiのログイン用メールアドレス
mixi_password ='PASS' #mixiのログイン用パスワード
twitter_username ='USER' #twitterユーザー名(メールアドレスは不可)
comment =' from twitter' #追加するフッタ(何も追加しない場合''にしてください)
interval = 120 # crontab interval
tweets = Array.new
url = 'http://twitter.com/statuses/user_timeline/'+twitter_username+'.xml'
xml = Nokogiri::XML(open(url))
xml.xpath('//status').each do |status|
if (Time.now - Time.parse(status.at('created_at').content) - interval) < 0
text = status.at('text').content.toutf8
unless /^@\w{1,15}\s/=~text
tweets.push(text)
end
else
break
end
end
if tweets.size > 0
agent = WWW::Mechanize.new
#mixiにログイン
page = agent.get("http://mixi.jp/")
form = page.forms.first
form["email"] = mixi_username
form["password"] = mixi_password
form.submit
#mixiエコーのページを取得
page = agent.get('http://mixi.jp/recent_echo.pl')
form = page.forms[1]
tweets = tweets.reverse
for i in 0...(tweets.size)
#mixiエコーに投稿
f = form['body'] =tweets[i]+comment
puts tweets[i]
form.click_button
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment