social_cleaner 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/lib/social_cleaner/twitr.rb +19 -19
- metadata +3 -3
data/lib/social_cleaner/twitr.rb
CHANGED
@@ -13,39 +13,39 @@ module SocialCleaner
|
|
13
13
|
|
14
14
|
|
15
15
|
def initialize(consumer_token, consumer_secret, access_token, access_secret, delete_after_days)
|
16
|
-
consumer_token = consumer_token
|
17
|
-
consumer_secret = consumer_secret
|
18
|
-
access_token = access_token
|
19
|
-
access_secret = access_secret
|
20
|
-
delete_after_days = delete_after_days
|
21
|
-
expire_ids = []
|
16
|
+
self.consumer_token = consumer_token
|
17
|
+
self.consumer_secret = consumer_secret
|
18
|
+
self.access_token = access_token
|
19
|
+
self.access_secret = access_secret
|
20
|
+
self.delete_after_days = delete_after_days
|
21
|
+
self.expire_ids = []
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
25
|
def create_client
|
26
26
|
# Let's get a Twitter Client created
|
27
|
-
oauth = Twitter::OAuth.new(consumer_token, consumer_secret)
|
28
|
-
oauth.authorize_from_access(access_token, access_secret)
|
27
|
+
oauth = Twitter::OAuth.new(self.consumer_token, self.consumer_secret)
|
28
|
+
oauth.authorize_from_access(self.access_token, self.access_secret)
|
29
29
|
|
30
|
-
client = Twitter::Base.new(oauth)
|
30
|
+
self.client = Twitter::Base.new(oauth)
|
31
31
|
end
|
32
32
|
|
33
33
|
|
34
34
|
def add_tweets_to_queue(statusses)
|
35
35
|
statusses.each do |status|
|
36
|
-
if Time.parse(status["created_at"]) < expire_before
|
36
|
+
if Time.parse(status["created_at"]) < self.expire_before
|
37
37
|
$stderr.puts "Queueing tweet delete status ID #{status["id"]} created at #{status["created_at"]} (#{status["text"]})."
|
38
38
|
$stdout.puts "#{status["id"]}\t\t#{status["created_at"]}\t\t#{status["text"]}"
|
39
|
-
expire_ids.push(status["id"])
|
39
|
+
self.expire_ids.push(status["id"])
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
|
45
45
|
def delete_tweets
|
46
|
-
expire_ids.each do |delete_status|
|
46
|
+
self.expire_ids.each do |delete_status|
|
47
47
|
$stderr.puts "Deleting #{delete_status}..."
|
48
|
-
client.status_destroy(delete_status)
|
48
|
+
self.client.status_destroy(delete_status)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -55,20 +55,20 @@ module SocialCleaner
|
|
55
55
|
create_client
|
56
56
|
|
57
57
|
# Expire deadline
|
58
|
-
expire_before = Time.now - (delete_after_days * 60 * 60 * 24)
|
58
|
+
self.expire_before = Time.now - (self.delete_after_days.to_i * 60 * 60 * 24)
|
59
59
|
|
60
|
-
$stderr.puts "Expiring all Twitter updates prior to #{expire_before.to_s}."
|
60
|
+
$stderr.puts "Expiring all Twitter updates prior to #{self.expire_before.to_s}."
|
61
61
|
|
62
62
|
# Iterate through timeline
|
63
63
|
# The old tweet id's don't contain a timestamp. maybe implement this for later?
|
64
|
-
add_tweets_to_queue(client.user_timeline)
|
65
|
-
add_tweets_to_queue(client.retweeted_by_me)
|
64
|
+
add_tweets_to_queue(self.client.user_timeline)
|
65
|
+
add_tweets_to_queue(self.client.retweeted_by_me)
|
66
66
|
|
67
67
|
# Now we'll sort the array, this will have the affect of putting the oldest items first in
|
68
68
|
# the list to be deleted.
|
69
|
-
expire_ids.sort!
|
69
|
+
self.expire_ids.sort!
|
70
70
|
|
71
|
-
$stderr.puts "Deleting #{expire_ids.length} tweets."
|
71
|
+
$stderr.puts "Deleting #{self.expire_ids.length} tweets."
|
72
72
|
|
73
73
|
# Now let's delete the stuff
|
74
74
|
# Note: the delete method is not rate limited.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Micha\xC3\xABl Rigart"
|