Class: Retrobot
- Inherits:
-
Object
show all
- Defined in:
- lib/retrobot.rb,
lib/retrobot/tweet.rb,
lib/retrobot/config.rb,
lib/retrobot/version.rb,
lib/retrobot/tweet_filters.rb,
lib/retrobot/tweet_filters/base.rb,
lib/retrobot/tweet_filters/tweet.rb,
lib/retrobot/tweet_filters/retweet.rb,
lib/retrobot/tweet_filters/unescape.rb,
lib/retrobot/tweet_filters/retro_days.rb,
lib/retrobot/tweet_filters/remove_atmark.rb,
lib/retrobot/tweet_filters/suppress_pattern.rb,
lib/retrobot/tweet_filters/add_in_reply_to_url.rb
Defined Under Namespace
Modules: TweetFilters
Classes: Config, Tweet
Constant Summary
collapse
- GEM_ROOT =
Pathname.new('..').expand_path(__dir__)
- VERSION =
'0.3.1'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(argv) ⇒ Retrobot
Returns a new instance of Retrobot.
23
24
25
|
# File 'lib/retrobot.rb', line 23
def initialize(argv)
@argv = argv
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
21
22
23
|
# File 'lib/retrobot.rb', line 21
def config
@config
end
|
Instance Method Details
#client ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/retrobot.rb', line 27
def client
@client ||= ::REST::Client.new do |config|
config.consumer_key = @config.consumer_key
config.consumer_secret = @config.consumer_secret
config.access_token = @config.access_token
config.access_token_secret = @config.access_secret
end
end
|
#csv ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/retrobot.rb', line 44
def csv
@csv ||= begin
= file_from_candidates(
@config.,
GEM_ROOT.join('tweets', 'tweets.csv'),
)
CSV.parse File.read()
end
end
|
#init_configuration ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/retrobot.rb', line 109
def init_configuration
options = parse_options()
@config = Config.new
config_yml = file_from_candidates(
options[:config], './retrobot.yml',
GEM_ROOT.join('retrobot.yml')
)
@config.load_yaml_file!(config_yml) if config_yml
@config.merge!(options)
client.current_user
end
|
#init_csv ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/retrobot.rb', line 54
def init_csv
csv.slice! 0
last_index = nil
csv.each_with_index.each do |line, i|
time = Time.parse line[3]
if time < @config.retro_days.ago
last_index = i
break;
end
end
csv.slice! last_index..-1
logger.info "Next update: \"#{csv.last[5]}\" at #{@config.retro_days.since(Time.parse(csv.last[3]))}"
end
|
#logger ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/retrobot.rb', line 36
def logger
@logger ||= begin
l = Logger.new($stdout)
l.level = @config.debug ? Logger::DEBUG : Logger::INFO
l
end
end
|
#main ⇒ Object
139
140
141
142
143
|
# File 'lib/retrobot.rb', line 139
def main
init_configuration
init_csv
end
|
#parse_options ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/retrobot.rb', line 124
def parse_options
options = {}
opt = OptionParser.new @argv
opt.banner = "Usage: #{$0} [OPTIONS]"
opt.on('--debug') { options[:debug] = true }
opt.on('--dryrun') { options[:dryrun] = true }
opt.on('--config file') {|v| options[:config] = v }
opt.on('--retro-days days') {|v| options[:retro_days] = v }
opt.on('--tweets-csv path') {|v| options[:tweets_csv] = v }
opt.parse!
options
end
|
#process_line(line) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/retrobot.rb', line 80
def process_line(line)
= .parse_line(line)
.each do |filter|
= filter.filter()
break unless
end
true
rescue ::Error
logger.error "#{$!} (#{$!.class})\n #{[email protected]("\n ")}"
true
rescue Retrobot::::RetryLater
false
end
|
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/retrobot.rb', line 96
def
return if
= []
<< ::RetroDays.new(self)
<< ::SuppressPattern.new(self) if @config.suppress_pattern
<< ::AddInReplyToUrl.new(self) if @config.add_in_reply_to_url
<< ::.new(self)
<< ::RemoveAtmark.new(self)
<< ::Unescape.new(self)
<< ::.new(self)
end
|
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/retrobot.rb', line 68
def
logger.info 'start'
loop do
line = csv.last
if process_line(line)
csv.pop
end
sleep @config.loop_interval
logger.debug '.'
end
end
|