-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-from-privacydata.rb
63 lines (56 loc) · 1.77 KB
/
backup-from-privacydata.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'yaml'
load "./twitter.rb"
last_file = "backup-from-privacydata.last"
cfg = YAML.load_file("settings.yml")["twitter"]
last_id = nil
begin
last_id = File.read(last_file)
rescue
#nothing
end
eraser = OnlineMemory::Twitter::OldTweetsEraser.new
eraser.client = client = OnlineMemory::Twitter::RateLimitedClient.new( cfg['credentials'] )
screen_name = client.screen_name
archive_file = "#{screen_name}/#{screen_name}-tweets.txt"
tweets_archive = OnlineMemory::Twitter::TweetArchiveFile.new( archive_file, last_id )
eraser.timeline = OnlineMemory::Twitter::FakeTimeline.new( tweets_archive, client)
eraser.storage = OnlineMemory::Twitter::Storage.new( cfg['storage_path'] )
begin
eraser.erase_older_than(cfg['expiration_time'])
ensure
File.write(last_file, tweets_archive.last_id_processed)
end
# $stdout.write "Backup and delete "
# processed = 0
# begin
# archive.each_tweet_id do |id|
# tries = 0
# begin
# tries += 1
# tweet = client.status(status_id)
# storage.store( tweet )
# date = DateTime.parse tweet.attrs[:created_at]
# if date < expiration
# client.tweet_destroy( tweet.attrs[:id] )
# $stdout.write "."
# processed += 1
# end
# rescue ::Twitter::Error::NotFound => error
# $stdout.write "x"
# rescue ::Twitter::Error::ClientError => error
# if tries < 3
# sleep 250
# $stderr.write "(ClientError #{error.to_s} #{tries})"
# client = OnlineMemory::Twitter::RateLimitedClient.new(cfg['credentials'])
# client.wait_if_overloaded = 250
# retry
# else
# raise
# end
# end
# end
# rescue ::Twitter::Error::TooManyRequests => error
# $stderr.write "(too many requests)"
# ensure
# $stdout.write " " + processed.to_s + " tweets"
# end