Created
March 22, 2012 00:15
-
-
Save MonkeyIsNull/2154357 to your computer and use it in GitHub Desktop.
Watches for the Plops of Twitter dropping your friends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'twitter' | |
require 'Getopt/Declare' | |
class Plop | |
attr_accessor :who, :seed_file, :peep_list | |
def initialize(who, seed_file='./plop.seed') | |
@who = who | |
@seed_file = seed_file | |
end | |
# Only two methods that actually use the Twitter gem | |
# Leave them here, same place, easy to switch out | |
def get_my_peeps | |
Twitter.friend_ids(@who).ids | |
end | |
def id_to_name(id) | |
Twitter.user(id).screen_name | |
end | |
# You must call this first | |
def pull_peeps_list | |
@peep_list = self.get_my_peeps() | |
self | |
end | |
# if seeding, open the seed and dump the follower_ids | |
def do_seeding | |
File.open(@seed_file, 'w+') do |f| | |
Marshal.dump @peep_list, f | |
end | |
self | |
end | |
def excrete(action, ids) | |
ids.each do |id| | |
puts "#{action} " + self.id_to_name(id) | |
end | |
end | |
def method_missing(sym, *args, &block) | |
excrete '*' + sym.to_s.upcase + '*', args[0] | |
self | |
end | |
def check_current_against_seed | |
change = false | |
File.open(@seed_file, 'r') do |f| | |
@seeds = Marshal.load f | |
end | |
report = { } | |
# diff seeded and get_my_peeps | |
some_plops = @seeds - @peep_list | |
# if seeds has more, Twitter dropped users, issue plops | |
if some_plops.size > 0 | |
change = true | |
plop some_plops | |
end | |
# if seeds has less, you added some users, issue pips | |
some_pips = @peep_list - @seeds | |
if some_pips.size > 0 | |
change = true | |
pip some_pips | |
end | |
if not change | |
puts "All clean!" | |
end | |
report['plops'] = some_plops | |
report['pips'] = some_pips | |
report | |
end | |
# yeah, just because | |
alias :check :check_current_against_seed | |
alias :pull :pull_peeps_list | |
alias :seed! :do_seeding | |
end | |
# | |
# This is for checking for those 'plops' of Twitter | |
# randomly dropping your friends. Also contains some | |
# 'pips' of friends being added. | |
# | |
args = Getopt::Declare.new(%q{ | |
<handle> Twitter handle [required] | |
-s Do seeding | |
}) | |
# You have to run a seeding at least the first | |
# time around | |
# Example: | |
# ruby plop.rb yourtwitterhandle -s | |
# (dumps a plop.seed in your current dir) | |
# Sometime later run | |
# ruby plop.rb yourtwitterhandle | |
# and it will spit out Plops and Pips | |
# Then run rerun the seeding. | |
if args['-s'] | |
Plop.new(args['<handle>']).pull.seed! | |
else | |
r = Plop.new(args['<handle>']).pull.check | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment