-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwittdiff.rb
49 lines (45 loc) · 1.09 KB
/
twittdiff.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'twitter'
unless ARGV[0]
puts "Needs args :p"
puts "./twittdiff username"
exit
end
TDHOME = File.join(ENV['HOME'],".twitdiff")
unless File.exists?(TDHOME)
Dir.mkdir(TDHOME)
end
followers = []
cursor = "-1"
while cursor != 0 do
fl = Twitter.follower_ids(ARGV[0],{"cursor"=>cursor})
cursor = fl.next_cursor
followers += fl.ids
sleep(2) # DON'T BREAK DA TWITTER
end
if File.exists?(File.join(TDHOME, ARGV[0]))
prev = File.readlines(File.join(TDHOME, ARGV[0])).map!{|x| x.chomp!.to_i}
new = (followers - prev)
if new.empty?
puts "No new followers"
else
puts "New followers:"
new.each do |cool|
puts "\t - #{Twitter.user(cool).name}"
end
end
diff = (prev-followers)
if diff.empty?
puts "No one stop following you"
else
puts "Not following you anymore:"
diff.each do |sucker|
begin
puts "\t - #{Twitter.user(sucker).name}"
rescue Twitter::Error::Forbidden
end
end
end
else
puts "First time twittdiff is ran, come back later"
end
File.open(File.join(TDHOME, ARGV[0]),'w').write(followers.join("\n")+"\n")