Skip to content

Instantly share code, notes, and snippets.

@Epictetus
Forked from rummelonp/remtter.rb
Created September 2, 2010 04:15
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 Epictetus/561812 to your computer and use it in GitHub Desktop.
Save Epictetus/561812 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rubytter'
TARGET_USER = 'mitukiii'
LOG = ARGV.any? {|arg| arg == '-l' || arg == '-log'}
CURRENT_DIR = File.dirname(File.expand_path(__FILE__))
OAUTH_YAML_NAME = 'mitukiii.jp.oauth.yaml'
FOLLOWERS_BEFORE_YAML_NAME = 'followers.txt'
oauth = YAML.load_file("#{CURRENT_DIR}/../#{OAUTH_YAML_NAME}")
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)
followers_current = t.followers_ids(TARGET_USER)
followers_before_yaml_path = "#{CURRENT_DIR}/#{FOLLOWERS_BEFORE_YAML_NAME}"
if File.exists?(followers_before_yaml_path)
followers_before = YAML.load_file(followers_before_yaml_path)
else
followers_before = followers_current
end
YAML.dump(followers_current, File.open(followers_before_yaml_path, 'w'))
followers_diff = followers_before - followers_current
followers_diff_names = followers_diff.collect do |follower_id|
begin
user = t.user(follower_id)
screen_name = "@#{user[:screen_name]}"
puts "unfollowed by #{screen_name}." if LOG
screen_name
rescue
nil
end
end.select {|name| !name.nil?}
if followers_diff_names.length > 0
message = "#{followers_diff_names.join(' ')} にアンフォローされました。"
puts message if LOG
t.direct_message(TARGET_USER, message)
else
puts "not unfollowed." if LOG
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment