Skip to content

Instantly share code, notes, and snippets.

@dariaphoebe
Forked from coilysiren/config.yaml
Created March 17, 2016 05:56
Show Gist options
  • Save dariaphoebe/26498f6dc92165e8f87f to your computer and use it in GitHub Desktop.
Save dariaphoebe/26498f6dc92165e8f87f to your computer and use it in GitHub Desktop.
Unfollows: (a) people who dont follow you back (b) people you haven't talked to (c) people who haven't posted in a month
require 'twitter' # gem install twitter
require 'capybara' # gem install capybara
require 'capybara/dsl'
# CONFIGS
exceptions = [
'XXXXXXXX',
]
# html credentials
username = 'XXXXXXXXXXX'
password = 'XXXXXXXXXXX'
# api crendentials
consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token_secret = 'XXXXXXXXXXXXXXXXXXXXXXX'
# FUNCTIONS
class Login
include Capybara::DSL
def do(username, password)
visit '/login'
find(".js-username-field").set(username)
find(".js-password-field").set(password)
find(".signin-wrapper .submit").click
end
end
class CheckForIF
include Capybara::DSL
def you_havent_talked(u1, u2)
begin
visit("/search?q=@#{u1.screen_name}+@#{u2.screen_name}")
find("ol#stream-items-id li.stream-item:first-child")
return false
rescue Capybara::ElementNotFound
return true
end
end
def they_dont_follow_you(u)
begin
visit("/@#{u.screen_name}")
find(".FollowStatus")
return false
rescue Capybara::ElementNotFound
return true
end
end
def they_havent_tweeted_recently(u)
one_month_ago = Time.now.to_i - 1*60*60*24*31
tweet_created = u.status.created_at.to_i
return tweet_created < one_month_ago
end
end
def do_unfollow(u, msg)
puts "#{u.name} (@#{u.screen_name}) http://twitter.com/@#{u.screen_name}"
puts "\t#{msg}"
@t.unfollow(u.screen_name)
end
# SETUP
# webkit
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.twitter.com'
Capybara.default_max_wait_time = 10
Login.new.do(username, password)
# api
t = @t = Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = access_token
config.access_token_secret = access_token_secret
end
u = t.user
following = t.friend_ids(u.id).to_a
# DO THE THING
for id in following
them = t.user(id)
if exceptions.include? them.screen_name
next
end
if CheckForIF.new.they_dont_follow_you(them)
do_unfollow(them, "Doesn't follow me")
elsif CheckForIF.new.they_havent_tweeted_recently(them)
do_unfollow(them, "Hasn't tweeted in a month")
elsif CheckForIF.new.you_havent_talked(u, them)
do_unfollow(them, "Hasn't said anything to me")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment