Skip to content

Instantly share code, notes, and snippets.

@dnpp73
Created December 12, 2010 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnpp73/737894 to your computer and use it in GitHub Desktop.
Save dnpp73/737894 to your computer and use it in GitHub Desktop.
Twitterで、その人のlistedを取得するだけ。
=begin
#{TARGET_USER} の listed を取得して yaml に吐き出します。
Rubytter と yaml が必要ですし、TwitterへのOAuth認証情報も別に用意しておきましょう。
getlisted.rb と同じ階層のディレクトリに "{screen_name}-{TwitterAppName}.yaml"
という感じのファイル名と書式で OAuth の認証情報を格納しておきます。
TARGET_USER と CLIENT_USER と CLIENT_SOURCE は適宜書き換えてください。
Willcom03のしょぼいキーボードと高速移動に弱すぎる回線を駆使して、電車の中で10分で書いたのであんまテストしてません。
見た感じ、51行目の [:name] を [:uri] や [:full_name] に書き換えると書式が変わりそうです。ぼくは試してません。
=end
require "rubygems"
require "yaml"
require "Rubytter"
LOG = true
TARGET_USER = "DNPP"
CLIENT_USER = "hoge"
CLIENT_SOURCE = "hoge"
CURRENT_DIR = File.dirname(File.expand_path(__FILE__))
OAUTH_YAML = "#{CLIENT_USER}-#{CLIENT_SOURCE}.yaml"
LISTS_FOLLOWERS_YAML = "#{TARGET_USER}-lists_followers.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 = Array.new ; next_cursor = -1
begin
while next_cursor != 0
print "---> fetching cursor #{next_cursor}" if LOG
res = t.lists_followers(TARGET_USER,:cursor=>next_cursor)
ary.concat res[:lists]
next_cursor = res[:next_cursor]
print " ... done\n" if LOG
end
rescue
print "\n---! Can't access to @#{TARGET_USER}'s listed\n"
print "---! wrong OAuth token or Twitter is overcapacity...\n"
exit
end
name_list = ary.collect {|i| i[:full_name] }
print "---> #{total} listed @#{TARGET_USER}\n" if LOG
YAML.dump(name_list,File.open("#{CURRENT_DIR}/#{LISTS_FOLLOWERS_YAML}",'w'))
print "---> #{CURRENT_DIR}/#{LISTS_FOLLOWERS_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