dbrady-twitterlost 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/twitterlost +37 -17
- metadata +1 -1
data/bin/twitterlost
CHANGED
@@ -13,32 +13,52 @@ require 'twitter'
|
|
13
13
|
require 'yaml'
|
14
14
|
|
15
15
|
base_dir = File.expand_path("~/.twitterlost/")
|
16
|
+
yaml_file = File.join(base_dir, "twitter.yml")
|
16
17
|
|
17
18
|
# Make sure the dir exists
|
18
19
|
FileUtils.mkdir_p(base_dir)
|
19
20
|
|
20
|
-
|
21
|
+
# Ensure twitter.yml exists; create default for user if not
|
22
|
+
if File.exists?(yaml_file)
|
23
|
+
cfg = YAML::load_file( yaml_file )
|
21
24
|
|
22
|
-
old_followers = IO.readlines(File.join(base_dir, "followers.txt")).map {|line| line.strip }.sort rescue []
|
25
|
+
old_followers = IO.readlines(File.join(base_dir, "followers.txt")).map {|line| line.strip }.sort rescue []
|
23
26
|
|
24
|
-
@client = Twitter::Client.new :login => cfg[:login], :password => cfg[:password]
|
27
|
+
@client = Twitter::Client.new :login => cfg[:login], :password => cfg[:password]
|
25
28
|
|
26
|
-
def followers_page(page)
|
27
|
-
|
28
|
-
end
|
29
|
+
def followers_page(page)
|
30
|
+
@client.my :followers, :page => page
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get all your followers. Loop is still kludgy.
|
34
|
+
p,f,followers=0,[],[]
|
35
|
+
followers += f.map { |u| u.screen_name } while (f=followers_page(p+=1)).any?
|
36
|
+
followers.sort!
|
37
|
+
|
38
|
+
lost_followers = old_followers - followers
|
39
|
+
new_followers = followers - old_followers
|
29
40
|
|
30
|
-
|
31
|
-
p,f,followers=0,[],[]
|
32
|
-
followers += f.map { |u| u.screen_name } while (f=followers_page(p+=1)).any?
|
33
|
-
followers.sort!
|
41
|
+
puts "You have #{followers.size} followers. Since the last time this program was run you lost #{lost_followers.size} followers and gained #{new_followers.size} new ones."
|
34
42
|
|
35
|
-
lost_followers
|
36
|
-
new_followers
|
43
|
+
puts lost_followers.map { |u| "LOST: #{u}" }
|
44
|
+
puts new_followers.map { |u| "NEW: #{u}" }
|
37
45
|
|
38
|
-
|
46
|
+
File.new(File.join(base_dir, "followers.txt"), "w").puts followers
|
47
|
+
File.new(File.join(base_dir, "lost.txt"), "a").puts lost_followers if lost_followers.any?
|
48
|
+
else
|
49
|
+
puts <<HELP
|
50
|
+
Welcome to Twitterlost! I cannot find your twitter.yml file.
|
39
51
|
|
40
|
-
|
41
|
-
|
52
|
+
I will write out a default file for you, but you will need to
|
53
|
+
edit the file to contain your twitter username and password.
|
54
|
+
|
55
|
+
Writing default file to #{yaml_file}...
|
56
|
+
HELP
|
57
|
+
|
58
|
+
File.open(yaml_file, 'w') do |f|
|
59
|
+
f.puts '---'
|
60
|
+
f.puts ':login: USERNAME'
|
61
|
+
f.puts ':password: PASSWORD'
|
62
|
+
end
|
63
|
+
end
|
42
64
|
|
43
|
-
File.new(File.join(base_dir, "followers.txt"), "w").puts followers
|
44
|
-
File.new(File.join(base_dir, "lost.txt"), "a").puts lost_followers if lost_followers.any?
|