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
64
65
66
67
68
69
70
71
72
|
# File 'lib/wtth.rb', line 19
def self.update
load_config
unless
puts 'You have not yet authorized WTTH to access Twitter.'
puts 'Please run `wtth init` first'
exit 1
end
to_welcome = CONFIG[:backlog]
if to_welcome == nil
to_welcome = get_new_zombies
elsif to_welcome.join(', ').length < 140
to_welcome = get_new_zombies + to_welcome
end
if to_welcome != []
this_batch = []
recovery = []
size = 0
until size > 140 or to_welcome.empty?
zombie = to_welcome.last
size += zombie.length
size += 2 if this_batch.length > 0
if size <= 140
this_batch << zombie
recovery << to_welcome.pop
end
end
CONFIG[:backlog] = to_welcome
this_batch.reverse!
begin
(this_batch.join(', '))
rescue Twitter::TwitterUnavailable
puts "TwitterUnavailable #{$!}"
CONFIG[:backlog] = to_welcome + recovery.reverse
rescue Twitter::TwitterError
puts "TwitterError #{$!}"
CONFIG[:backlog] = to_welcome + recovery.reverse
end
end
save_config
end
|