Created
September 19, 2009 01:53
-
-
Save eiel/189379 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -*- | |
require 'rubygems' | |
require 'mechanize' | |
require 'rubytter' | |
###################### | |
#mixiのログイン情報 | |
###################### | |
mixi_username ='[email protected]' #mixiのログイン用メールアドレス | |
mixi_password ='xxxxxxx' #mixiのログイン用パスワード | |
###################### | |
#twitterのログイン情報 | |
###################### | |
twitter_username ='xxxxx' #twitterユーザー名(メールアドレスは不可) | |
twitter_password ='xxxxxxx' #twitterログイン用パスワード | |
##########8############ | |
#その他設定項目(必要に応じて変更してください) | |
###################### | |
posted_num_file ='posted_num.dat' #mixiに投稿済みつぶやきの番号を記録するファイル | |
comment ='[From Twitter]' #追加するフッタ(何も追加しない場合''にしてください) | |
def post_mixi(user, pass, tweets, surfix) | |
agent = WWW::Mechanize.new | |
#mixiにログイン | |
page = agent.get("http://mixi.jp/") | |
form = page.forms.first | |
form["email"] = user | |
form["password"] = pass | |
form.submit | |
#mixiエコーのページを取得 | |
page = agent.get('http://mixi.jp/recent_echo.pl') | |
form = page.forms[1] | |
# replyの削除 | |
tweets = tweets.reject{ |i| /^@/ =~ i } | |
tweets.reverse.each do |t| | |
form['body'] = t + surfix | |
form.submit | |
# puts t + preffix | |
end | |
end | |
# mixiにポスト済みの番号の取得 | |
begin | |
posted_num = File.open(posted_num_file).read.to_i | |
rescue | |
posted_num = 0 | |
end | |
# つぶやきを取得 | |
tw = Rubytter.new(twitter_username,twitter_password) | |
timeline = tw.user_timeline(twitter_username) | |
tweets = timeline | |
.select{ |i| i.user.statuses_count > posted_num } | |
.map{ |i| i.text } | |
latest_num = timeline[0].user.statuses_count | |
post_mixi(mixi_username, mixi_password, tweets, comment) | |
File.open(posted_num_file,"w") do |f| | |
f.puts latest_num | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment