social_cleaner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +21 -0
- data/lib/social_cleaner/twitr.rb +53 -0
- data/lib/social_cleaner.rb +9 -0
- metadata +82 -0
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
README (draft)
|
2
|
+
======
|
3
|
+
|
4
|
+
install the gem:
|
5
|
+
|
6
|
+
gem install social_cleaner
|
7
|
+
|
8
|
+
Then make a ruby script:
|
9
|
+
|
10
|
+
#!/usr/bin/ruby
|
11
|
+
#
|
12
|
+
# Get requires out of the way
|
13
|
+
require 'rubygems'
|
14
|
+
gem 'social_cleaner'
|
15
|
+
require 'social_cleaner'
|
16
|
+
|
17
|
+
cleaner = SocialCleaner::Twitr.new(consumer_token, consumer_secret, access_token, access_secret, delete_after_days)
|
18
|
+
cleaner.delete_messages
|
19
|
+
|
20
|
+
|
21
|
+
Save the file, make it executeable and run like ./script.rb or put it in a cronjob
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module SocialCleaner
|
2
|
+
|
3
|
+
class Twitr
|
4
|
+
|
5
|
+
attr_accessor :consumer_token, :consumer_secret, :access_token, :access_secret, :delete_after_days
|
6
|
+
|
7
|
+
def initialize(consumer_token, consumer_secret, access_token, access_secret, delete_after_days)
|
8
|
+
self.consumer_token = consumer_token
|
9
|
+
self.consumer_secret = consumer_secret
|
10
|
+
self.access_token = access_token
|
11
|
+
self.access_secret = access_secret
|
12
|
+
self.delete_after_days = delete_after_days
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete_messages
|
16
|
+
# Let's get a Twitter Client created
|
17
|
+
oauth = Twitter::OAuth.new(consumer_token, consumer_secret)
|
18
|
+
oauth.authorize_from_access(access_token, access_secret)
|
19
|
+
|
20
|
+
client = Twitter::Base.new(oauth)
|
21
|
+
|
22
|
+
# Expire deadline
|
23
|
+
expire_before = Time.now - (delete_after_days * 60 * 60 * 24)
|
24
|
+
expire_ids = []
|
25
|
+
|
26
|
+
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|
|
32
|
+
if Time.parse(status["created_at"]) < expire_before
|
33
|
+
puts "Queueing delete status ID #{status["id"]} created at #{status["created_at"]} (#{status["text"]})."
|
34
|
+
expire_ids.push(status["id"])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Now we'll sort the array, this will have the affect of putting the oldest items first in
|
39
|
+
# the list to be deleted.
|
40
|
+
expire_ids.sort!
|
41
|
+
|
42
|
+
puts "Deleting #{expire_ids.length} tweets."
|
43
|
+
|
44
|
+
# Now let's delete the stuff
|
45
|
+
# Note: the delete method is not rate limited.
|
46
|
+
expire_ids.each do |delete_status|
|
47
|
+
puts "Deleting #{delete_status}..."
|
48
|
+
client.status_destroy(delete_status)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: social_cleaner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Micha\xC3\xABl Rigart"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-24 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: twitter
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Cleans up your social messages
|
36
|
+
email: michael@netronix.be
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- lib/social_cleaner.rb
|
46
|
+
- lib/social_cleaner/twitr.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://www.netronix.be
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: nowarning
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Social Cleaner
|
81
|
+
test_files: []
|
82
|
+
|