Created
December 12, 2010 07:02
-
-
Save dnpp73/737896 to your computer and use it in GitHub Desktop.
Twitterのlistに放り込んでるアカウントのscreen_nameをyamlに書き出すだけ。
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
=begin | |
たまに screen_name 変える人がいたりして、クライアントの振り分けルールと list を同期したりするときに使う用に書きました。 | |
Rubytter と yaml が必要ですし、TwitterへのOAuth認証情報も別に用意しておきましょう。 | |
list2yaml.rb と同じディレクトリに "{screen_name}-{TwitterAppName}.yaml" という感じのファイル名と書式で OAuth の認証情報を格納しておきます。 | |
TARGET_USER と TARGET_LIST_NAME と CLIENT_USER と CLIENT_SOURCE は適宜書き換えてください。 | |
screen_name の配列を yaml に出力するだけなので、適当なエディタとかの置換機能使ったり、整形するプログラム書いたりして整形すればいいと思います。 | |
=end | |
require "rubygems" | |
require "yaml" | |
require "Rubytter" | |
LOG = true | |
TARGET_USER = "DNPP" | |
TARGET_LIST_NAME = "" | |
CLIENT_USER = "hoge" | |
CLIENT_SOURCE = "hoge" | |
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) | |
OAUTH_YAML = "#{CLIENT_USER}-#{CLIENT_SOURCE}.yaml" | |
LIST_MEMBERS_YAML = "#{TARGET_USER}-#{TARGET_LIST_NAME}-list_members.yaml" | |
# OAuth周りの認証処理 | |
begin | |
oauth = YAML.load_file("#{CURRENT_DIR}/#{OAUTH_YAML}") | |
rescue | |
print "---! Can't open #{OAUTH_YAML}\n" | |
exit | |
end | |
consumer = OAuth::Consumer.new(oauth["consumer_key"],oauth["consumer_secret"],:site => "http://twitter.com") | |
token = OAuth::AccessToken.new(consumer, oauth["oauth_token"],oauth["oauth_token_secret"]) | |
t = OAuthRubytter.new(token) | |
# listの取得と格納 | |
ary = [] | |
next_cursor = -1 | |
begin | |
while next_cursor != 0 | |
print "---> fetching cursor #{next_cursor}" if LOG | |
res = t.list_members(TARGET_USER,TARGET_LIST_NAME,:cursor=>next_cursor) | |
ary.concat res[:users] | |
next_cursor = res[:next_cursor] | |
print " ... done\n" if LOG | |
end | |
rescue | |
print "\n---! Can't access to @#{TARGET_USER}/#{TARGET_LIST_NAME}\n" | |
print "---! There is no list or Protected list or Twitter is overcapacity...\n" | |
exit | |
end | |
screen_name_list = [] | |
total = 0 | |
ary.each_with_index do |elem,i| | |
screen_name_list << ary[i][:screen_name] | |
total = total + 1 | |
end | |
print "---> #{total} accounts in @#{TARGET_USER}/#{TARGET_LIST_NAME}\n" if LOG | |
YAML.dump(screen_name_list,File.open("#{CURRENT_DIR}/#{LIST_MEMBERS_YAML}",'w')) | |
print "---> #{CURRENT_DIR}/#{LIST_MEMBERS_YAML}\n" if LOG | |
print "---> enjoy!\n" if LOG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment