Created
March 25, 2010 18:23
-
-
Save yukikaoru/343926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# | |
#= ついったーとmixiボイスを同期する | |
# | |
require "rubygems" | |
require "mechanize" | |
require "rubytter" | |
# mixiのログイン情報 | |
mixi_id = 'mixi_id' | |
mixi_passwd = 'mixi_passwd' | |
# ついったーのログイン情報 | |
twitter_id = 'tw_id' | |
twitter_passwd = 'tw_passwd' | |
# mixiにログイン | |
agent = Mechanize.new | |
page = agent.get("http://mixi.jp/") | |
form = page.forms.first | |
form["email"] = mixi_id | |
form["password"] = mixi_passwd | |
form.submit | |
# mixiボイスの投稿フォームを取得 | |
page = agent.get("http://mixi.jp/recent_voice.pl") | |
form = nil | |
page.forms.each do |f| | |
if f.action == "add_voice.pl" | |
form = f | |
break | |
end | |
end | |
raise "mixi login failure." if form.nil? | |
# ついったーから最新の発言を取得 | |
tweets = [] | |
Rubytter.new(twitter_id,twitter_passwd).user_timeline(twitter_id).each do |t| | |
tweets << t.text.tr("\n"," ") | |
end | |
tweets = tweets.reverse.map{|v| v.chomp} | |
# ポスト済のログファイルを読み込んで書き込み済のものを排除 | |
posted_log_file = File.expand_path("posted.log", File.dirname(__FILE__)) | |
posted = [] | |
if File.exist?(posted_log_file) | |
open(posted_log_file, "r"){|f| posted = f.readlines} | |
end | |
posts = tweets.dup | |
posted.each do |p| | |
posts.delete(p.chomp) | |
end | |
exit if posts.empty? | |
# ログファイルを更新 | |
open(posted_log_file, "w"){|f| f.puts tweets.join("\n")} | |
# mixiボイスへの投稿 | |
posts.each do |p| | |
# replyは無視 | |
if p !~ /@[0-9a-zA-Z_]/ && p.index("4sq.com").nil? | |
form["body"] = p | |
form.submit | |
sleep(2) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment