Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
require 'json'
require 'faraday'
TWITTER_USER = "your_username_here"
TIMEOUT = 1 # increment this if you're getting a lot of rate limit errors
# get these from dev.twitter.com
CONSUMER_KEY = "blahblah"
CONSUMER_SECRET = "blahblah"
OAUTH_TOKEN = "blahblah"
OAUTH_TOKEN_SECRET = "blahblah"
Twitter.configure do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.oauth_token = OAUTH_TOKEN
config.oauth_token_secret = OAUTH_TOKEN_SECRET
end
followings = Twitter.friend_ids(TWITTER_USER, {:cursor => -1}) # cursor maybe not necessary? idk
puts "let's begin... #{followings.ids.size} accounts to look at here"
# tip: if you just want to play with this script (and not actually trudge through all of your followings) replace
# followings.ids.map
# with
# followings.ids.sample(10).map
users_and_times = followings.ids.map do |id|
begin
sleep TIMEOUT
name = Twitter.user(id).name
puts "fetching info for #{name}"
{:id => id,
:name => name,
:username => Twitter.user(id).username,
:newest_timestamp => Twitter.user_timeline(id).first.created_at}
rescue Twitter::Error::TooManyRequests => error
puts "ERROR: too many API requests; pausing #{error.rate_limit.reset_in} seconds"
sleep error.rate_limit.reset_in
retry
end
end
puts "sorting"
users_and_times.sort_by! do |user|
user[:newest_timestamp]
end
THRESHOLD_IN_DAYS = 7 # <-- here's where you set your threshold
now = Time.now
users_and_times.each do |user|
diff_in_days = ( (now - user[:newest_timestamp]) / (60*60*24) ).ceil
if (diff_in_days >= THRESHOLD_IN_DAYS) then
puts "#{user[:username]} (#{user[:name]}) hasn't tweeted in #{diff_in_days} days"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment