camptweet 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/bin/camptweetd_base +3 -1
- data/camptweet.gemspec +10 -7
- data/lib/camptweet/bot.rb +86 -18
- data/lib/camptweet.rb +2 -0
- metadata +13 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
v0.8.3. Added support for broadcasting Twitter (Summize) search results and other RSS feed results to Campfire.
|
2
|
+
|
1
3
|
v0.8.2. Attempt automatic Twitter reconnects.
|
2
4
|
|
3
5
|
v0.8.1. Use standard logger. Bot class restructured. Better error handling. Better Campfire spam protection.
|
data/bin/camptweetd_base
CHANGED
@@ -4,8 +4,10 @@ require 'camptweet'
|
|
4
4
|
|
5
5
|
Camptweet::Bot.new do |camptweet|
|
6
6
|
camptweet.twitter_users = ['bdainton']
|
7
|
+
camptweet.twitter_search_terms = ['fiveruns']
|
8
|
+
camptweet.feed_urls = ['http://github.com/repositories.atom']
|
7
9
|
camptweet.campfire_subdomain = 'mycompany'
|
8
|
-
camptweet.campfire_use_ssl = true
|
10
|
+
camptweet.campfire_use_ssl = true
|
9
11
|
camptweet.campfire_room = 'Room Name'
|
10
12
|
camptweet.campfire_email = 'foo@mycompany.com'
|
11
13
|
camptweet.campfire_password = 'foo_password'
|
data/camptweet.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Camptweet-0.8.
|
2
|
+
# Gem::Specification for Camptweet-0.8.3
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{camptweet}
|
7
|
-
s.version = "0.8.
|
7
|
+
s.version = "0.8.3"
|
8
8
|
|
9
9
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Brian Dainton"]
|
13
|
-
s.date = %q{2008-
|
14
|
-
s.description = %q{A simple daemon that polls for updated Twitter statuses and posts
|
13
|
+
s.date = %q{2008-07-03}
|
14
|
+
s.description = %q{A simple daemon that polls for updated Twitter statuses, Summize search results, and RSS/Atom feed items and posts them to a Campfire room.}
|
15
15
|
s.email = %q{}
|
16
16
|
s.executables = ["camptweet", "camptweetd_base"]
|
17
17
|
s.extra_rdoc_files = ["bin/camptweet", "bin/camptweetd_base", "CHANGELOG", "lib/camptweet/bot.rb", "lib/camptweet.rb", "LICENSE", "README.rdoc"]
|
@@ -22,10 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
s.rubyforge_project = %q{camptweet}
|
24
24
|
s.rubygems_version = %q{1.1.1}
|
25
|
-
s.summary = %q{A simple daemon that polls for updated Twitter statuses and posts
|
25
|
+
s.summary = %q{A simple daemon that polls for updated Twitter statuses, Summize search results, and RSS/Atom feed items and posts them to a Campfire room.}
|
26
26
|
|
27
27
|
s.add_dependency(%q<twitter4r>, [">= 0.3.0"])
|
28
28
|
s.add_dependency(%q<tinder>, [">= 0.1.6"])
|
29
|
+
s.add_dependency(%q<simple-rss>, [">= 0"])
|
29
30
|
end
|
30
31
|
|
31
32
|
|
@@ -39,9 +40,11 @@ end
|
|
39
40
|
#
|
40
41
|
# Echoe.new('camptweet') do |p|
|
41
42
|
# p.author = "Brian Dainton"
|
42
|
-
# p.summary = "A simple daemon that polls for updated Twitter statuses
|
43
|
+
# p.summary = "A simple daemon that polls for updated Twitter statuses,
|
44
|
+
# Summize search results, and RSS/Atom feed items and posts
|
45
|
+
# them to a Campfire room."
|
43
46
|
# p.url = "http://github.com/bdainton/camptweet"
|
44
|
-
# p.dependencies = ["twitter4r >=0.3.0", "tinder >=0.1.6"]
|
47
|
+
# p.dependencies = ["twitter4r >=0.3.0", "tinder >=0.1.6", "simple-rss"]
|
45
48
|
# end
|
46
49
|
#
|
47
50
|
#
|
data/lib/camptweet/bot.rb
CHANGED
@@ -2,6 +2,8 @@ module Camptweet
|
|
2
2
|
class Bot
|
3
3
|
|
4
4
|
attr_accessor :twitter_users
|
5
|
+
attr_accessor :twitter_search_terms
|
6
|
+
attr_accessor :feed_urls
|
5
7
|
attr_accessor :campfire_subdomain
|
6
8
|
attr_accessor :campfire_use_ssl
|
7
9
|
attr_accessor :campfire_room
|
@@ -13,7 +15,8 @@ module Camptweet
|
|
13
15
|
|
14
16
|
def initialize(&block)
|
15
17
|
yield self if block_given?
|
16
|
-
init_log
|
18
|
+
init_log
|
19
|
+
add_twitter_search_urls_to_feed_urls
|
17
20
|
connect_to_twitter
|
18
21
|
connect_to_campfire
|
19
22
|
login_to_campfire
|
@@ -21,35 +24,46 @@ module Camptweet
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def run
|
24
|
-
last_statuses =
|
27
|
+
last_statuses = {}
|
28
|
+
last_feed_items = {}
|
25
29
|
|
26
30
|
loop do
|
27
31
|
begin
|
28
32
|
new_statuses = []
|
33
|
+
new_feed_items = []
|
34
|
+
|
35
|
+
# check for updated tweets
|
29
36
|
checking_twitter_timelines do |user, status|
|
30
37
|
if last_statuses[user].nil?
|
31
|
-
# Only broadcast this tweet if we have an initial status against
|
32
|
-
# which we can compare it.
|
33
38
|
last_statuses[user] = status
|
34
39
|
elsif status.created_at > last_statuses[user].created_at
|
35
|
-
# Only consider the most recent tweet.
|
36
40
|
new_statuses << status
|
37
41
|
last_statuses[user] = status
|
38
42
|
end
|
39
43
|
end
|
40
|
-
|
44
|
+
|
45
|
+
# post any updated tweets to campfire
|
41
46
|
new_statuses.sort_by(&:created_at).each do |status|
|
42
47
|
begin
|
43
|
-
|
44
|
-
log.info message
|
45
|
-
room.speak message
|
46
|
-
log.debug "(Campfire updated)"
|
48
|
+
send_message_to_campfire "[#{status.user.name}] #{status.text}"
|
47
49
|
rescue Timeout::Error => e
|
48
50
|
log.info "Campfire timeout: (#{e.message})"
|
49
51
|
ensure
|
50
52
|
sleep 2
|
51
53
|
end
|
52
54
|
end
|
55
|
+
|
56
|
+
# check for updated rss feed items and post them to campfire
|
57
|
+
checking_feeds do |feed_url, feed, item|
|
58
|
+
log.debug "...checking last_feed_item for this feed: #{last_feed_items[feed_url].blank? ? 'no item' : last_feed_items[feed_url].title}"
|
59
|
+
if last_feed_items[feed_url].blank?
|
60
|
+
last_feed_items[feed_url] = item
|
61
|
+
elsif timestamp_for(item) > timestamp_for(last_feed_items[feed_url])
|
62
|
+
last_feed_items[feed_url] = item
|
63
|
+
send_message_to_campfire feed_item_message_for(feed, item)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
53
67
|
rescue => e
|
54
68
|
log.error e.message
|
55
69
|
log.error e.backtrace
|
@@ -61,6 +75,18 @@ module Camptweet
|
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
78
|
+
def twitter_users
|
79
|
+
@twitter_users ||= []
|
80
|
+
end
|
81
|
+
|
82
|
+
def twitter_search_terms
|
83
|
+
@twitter_search_terms ||= []
|
84
|
+
end
|
85
|
+
|
86
|
+
def feed_urls
|
87
|
+
@feed_urls ||= []
|
88
|
+
end
|
89
|
+
|
64
90
|
private
|
65
91
|
|
66
92
|
def connect_to_twitter
|
@@ -109,14 +135,6 @@ module Camptweet
|
|
109
135
|
verbose
|
110
136
|
end
|
111
137
|
|
112
|
-
def initial_statuses
|
113
|
-
returning statuses = {} do
|
114
|
-
checking_twitter_timelines do |user, status|
|
115
|
-
statuses[user] = status
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
138
|
def checking_twitter_timelines
|
121
139
|
twitter_users.each do |user|
|
122
140
|
begin
|
@@ -137,6 +155,56 @@ module Camptweet
|
|
137
155
|
end
|
138
156
|
end
|
139
157
|
end
|
158
|
+
|
159
|
+
def checking_feeds
|
160
|
+
feed_urls.each do |feed_url|
|
161
|
+
begin
|
162
|
+
log.debug "Checking '#{feed_url}'..."
|
163
|
+
rss = SimpleRSS.parse(open(feed_url))
|
164
|
+
if rss.items.blank?
|
165
|
+
log.debug "No items in this RSS feed."
|
166
|
+
next
|
167
|
+
end
|
168
|
+
item = rss.items.first
|
169
|
+
log.debug "First item has title #{item.title} with timestamp #{timestamp_for(item)}"
|
170
|
+
yield feed_url, rss, item
|
171
|
+
rescue => e
|
172
|
+
log.error "Error in parsing feed: (#{e.message})"
|
173
|
+
log.error e.backtrace
|
174
|
+
ensure
|
175
|
+
log.debug " ...done."
|
176
|
+
sleep 2
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def timestamp_for(feed_item)
|
182
|
+
return feed_item.published if feed_item.published
|
183
|
+
return feed_item.pubDate if feed_item.pubDate
|
184
|
+
return feed_item.updated if feed_item.updated
|
185
|
+
return feed_item.dc_date if feed_item.dc_date
|
186
|
+
log.debug "Couldn't find a date for feed item #{feed_item.inspect}"
|
187
|
+
end
|
188
|
+
|
189
|
+
def send_message_to_campfire(message)
|
190
|
+
begin
|
191
|
+
log.info message
|
192
|
+
room.speak CGI.unescapeHTML(message)
|
193
|
+
log.debug "(Campfire updated)"
|
194
|
+
rescue Timeout::Error => e
|
195
|
+
log.info "Campfire timeout: (#{e.message})"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def feed_item_message_for(feed, item)
|
200
|
+
"[#{feed.title}] #{item.title} (#{item.author}): #{item.link}"
|
201
|
+
end
|
202
|
+
|
203
|
+
def add_twitter_search_urls_to_feed_urls
|
204
|
+
twitter_search_terms.each do |search_term|
|
205
|
+
feed_urls << "http://summize.com/search.atom?q=#{search_term}"
|
206
|
+
end
|
207
|
+
end
|
140
208
|
|
141
209
|
end
|
142
210
|
end
|
data/lib/camptweet.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camptweet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Dainton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,16 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: 0.1.6
|
32
32
|
version:
|
33
|
-
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: simple-rss
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
description: A simple daemon that polls for updated Twitter statuses, Summize search results, and RSS/Atom feed items and posts them to a Campfire room.
|
34
43
|
email: ""
|
35
44
|
executables:
|
36
45
|
- camptweet
|
@@ -86,6 +95,6 @@ rubyforge_project: camptweet
|
|
86
95
|
rubygems_version: 1.1.1
|
87
96
|
signing_key:
|
88
97
|
specification_version: 2
|
89
|
-
summary: A simple daemon that polls for updated Twitter statuses and posts
|
98
|
+
summary: A simple daemon that polls for updated Twitter statuses, Summize search results, and RSS/Atom feed items and posts them to a Campfire room.
|
90
99
|
test_files: []
|
91
100
|
|