Skip to content

Instantly share code, notes, and snippets.

@todesking
Created October 1, 2010 04:38
Show Gist options
  • Save todesking/605747 to your computer and use it in GitHub Desktop.
Save todesking/605747 to your computer and use it in GitHub Desktop.
Twitのお気に入りIDタブの設定を公式リストと同期させる
# Twitのお気に入りIDタブをlistと同期させる
# 使用法
# - リストと同期したいお気に入りIDタブの名前を list:リスト名 にする
# - Twitを終了する
# - このファイルをTwitのインストールフォルダに置き、実行するとリストがTwitに反映される
# - Twitを再起動
#
# 依存gem: Pit,twitter
# Pitに、'ユーザ名@twitter'という名前で以下の項目を登録しとく必要がある(てきとうにがんばってください)
# - consumer_token
# - consumer_token
# - access_token
# - access_token_secret
#
require 'rubygems'
require 'twitter'
require 'pit'
def connect pit_name
user_conf=Pit.get(pit_name,:require=>{
'consumer_token'=>'consumer token',
'consumer_secret'=>'consumer secret',
'access_token'=>'access token',
'access_token_secret'=>'access token secret'
})
Twitter.configure {|conf|
conf.consumer_key=user_conf['consumer_token']
conf.consumer_secret=user_conf['consumer_secret']
conf.oauth_token=user_conf['access_token']
conf.oauth_token_secret=user_conf['access_token_secret']
}
#oauth=Twitter::OAuth.new(user_conf['consumer_token'],user_conf['consumer_secret'])
#oauth.authorize_from_access(user_conf['access_token'],user_conf['access_token_secret'])
#return Twitter::Base.new(oauth)
return Twitter::Client.new
end
def list_members(twitter,user,list)
m=[]
l=twitter.list_members(user,list)
m << l.users.map{|x|x.screen_name}
while l.next_cursor>0
begin
l=twitter.list_members(user,list,:cursor=>l.next_cursor)
rescue Twitter::InformTwitter
puts ' retry'
sleep 1.0
next
rescue Twitter::Unavailable
puts ' retry'
sleep 1.0
next
rescue Errno::ECONNRESET
puts ' retry'
sleep 1.0
next
end
m << l.users.map{|x|x.screen_name}
end
return m
end
# returns: {:user_name=>user_name, :list=>{list_name => file_name}}
def get_ini
ini_file=File.join(File.dirname(__FILE__),'Twit.ini')
user_name=''
target={}
open(ini_file){|f|
while f.gets
line=$_.strip
target[$2]="Twit.fav#{$1}" if line =~ /^FavIDLabel(\d*)=list:([-_\w]+)$/
user_name=$1 if line =~ /^Username=(\w+)$/
end
}
return {:user_name=>user_name, :list=>target}
end
if __FILE__ == $0
info=get_ini
twitter=connect "#{info[:user_name]}@twitter"
info[:list].each{|list,file|
puts "#{list} => #{file}"
members=list_members(twitter,info[:user_name],list)
open(file,'w'){|f|
f.puts members
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment