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