bdainton-camptweet 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/LICENSE +21 -0
- data/Manifest +9 -0
- data/README.rdoc +51 -0
- data/bin/camptweet +18 -0
- data/bin/camptweetd_base +14 -0
- data/camptweet.gemspec +14 -0
- data/init.rb +1 -0
- data/lib/camptweet.rb +11 -0
- data/lib/camptweet/bot.rb +119 -0
- metadata +80 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.8. First Version
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 Brian Dainton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= CampTweet
|
2
|
+
|
3
|
+
== Synopsis
|
4
|
+
|
5
|
+
A simple daemon that polls for updated Twitter statuses and posts them to a Campfire room.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Install the gem and its dependencies:
|
10
|
+
|
11
|
+
sudo gem install twitter4r
|
12
|
+
sudo gem install tinder
|
13
|
+
sudo gem install bdainton-camptweet -s http://gems.github.com/
|
14
|
+
|
15
|
+
From the commandline, run:
|
16
|
+
|
17
|
+
camptweet
|
18
|
+
|
19
|
+
This creates a 'camptweetd' file.
|
20
|
+
|
21
|
+
Edit this file to specify the Twitter user screen names for which you'd like to grab status information, the desired Campfire subdomain and room name, and the Campfire email/password with which this daemon should use to connect.
|
22
|
+
|
23
|
+
Then, run:
|
24
|
+
|
25
|
+
./camptweetd
|
26
|
+
|
27
|
+
The latest Twitter statuses for the users you have specified will be broadcast into your Campfire room. Nohup and background this script excecution to keep it going (nohup ./camptweetd &).
|
28
|
+
|
29
|
+
== License
|
30
|
+
|
31
|
+
The MIT License
|
32
|
+
|
33
|
+
Copyright (c) 2008 Brian Dainton
|
34
|
+
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
36
|
+
of this software and associated documentation files (the "Software"), to deal
|
37
|
+
in the Software without restriction, including without limitation the rights
|
38
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
39
|
+
copies of the Software, and to permit persons to whom the Software is
|
40
|
+
furnished to do so, subject to the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be included in
|
43
|
+
all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
46
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
47
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
48
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
49
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
50
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
51
|
+
THE SOFTWARE.
|
data/bin/camptweet
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
destination = ARGV[0] || Dir.pwd
|
6
|
+
unless File.directory?(destination)
|
7
|
+
abort "CampTweet: #{destination} does not exist; cannot create CampTweet daemon script"
|
8
|
+
end
|
9
|
+
|
10
|
+
if File.exists?(File.join(destination, 'camptweetd'))
|
11
|
+
abort "CampTweet: CampTweet daemon script already exists at #{destination}. Exiting."
|
12
|
+
end
|
13
|
+
|
14
|
+
origin = File.join(File.dirname(__FILE__), "camptweetd_base")
|
15
|
+
FileUtils.mkdir_p File.dirname(destination)
|
16
|
+
FileUtils.cp origin, File.join(destination, 'camptweetd')
|
17
|
+
|
18
|
+
STDERR.puts "CampTweet daemon script created at #{destination}."
|
data/bin/camptweetd_base
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'camptweet'
|
4
|
+
|
5
|
+
Camptweet::Bot.new do |camptweet|
|
6
|
+
camptweet.twitter_users = ['bdainton']
|
7
|
+
camptweet.campfire_subdomain = 'mycompany'
|
8
|
+
camptweet.campfire_use_ssl = true
|
9
|
+
camptweet.campfire_room = 'Room Name'
|
10
|
+
camptweet.campfire_email = 'foo@mycompany.com'
|
11
|
+
camptweet.campfire_password = 'foo_password'
|
12
|
+
camptweet.verbose = false
|
13
|
+
camptweet.logfile = 'camptweet.log'
|
14
|
+
end.run
|
data/camptweet.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'camptweet'
|
3
|
+
s.version = '0.8.0'
|
4
|
+
s.authors = ['Brian Dainton']
|
5
|
+
s.email = 'brian.dainton@gmail.com'
|
6
|
+
s.homepage = 'http://github.com/bdainton/camptweet'
|
7
|
+
s.summary = 'A simple daemon that polls for updated Twitter statuses and posts them to a Campfire room.'
|
8
|
+
s.description = s.summary
|
9
|
+
s.require_path = 'lib'
|
10
|
+
s.executables = ["camptweet", "camptweetd_base"]
|
11
|
+
s.files = ["bin/camptweet", "bin/camptweetd_base", "CHANGELOG", "init.rb", "lib/camptweet/bot.rb", "lib/camptweet.rb", "LICENSE", "README.rdoc", "Manifest", "camptweet.gemspec"]
|
12
|
+
s.add_dependency('twitter4r', [">= 0.3.0"])
|
13
|
+
s.add_dependency('tinder', [">= 0.1.6"])
|
14
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'camptweet'
|
data/lib/camptweet.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
require 'time'
|
4
|
+
require 'twitter'
|
5
|
+
require 'tinder'
|
6
|
+
|
7
|
+
Dir[File.join(File.dirname(__FILE__), 'camptweet/**/*.rb')].sort.each { |lib| require lib }
|
8
|
+
|
9
|
+
module Camptweet
|
10
|
+
class Error < StandardError; end
|
11
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module Camptweet
|
2
|
+
class Bot
|
3
|
+
|
4
|
+
attr_accessor :twitter_users
|
5
|
+
attr_accessor :campfire_subdomain
|
6
|
+
attr_accessor :campfire_use_ssl
|
7
|
+
attr_accessor :campfire_room
|
8
|
+
attr_accessor :campfire_email
|
9
|
+
attr_accessor :campfire_password
|
10
|
+
attr_accessor :verbose
|
11
|
+
attr_accessor :logfile
|
12
|
+
attr_reader :twitter, :room
|
13
|
+
|
14
|
+
def initialize(&block)
|
15
|
+
yield self if block_given?
|
16
|
+
@twitter = Twitter::Client.new
|
17
|
+
unless @twitter
|
18
|
+
log "Unable to establish connection to Twitter. Exiting."
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
log "Established connection to Twitter."
|
22
|
+
|
23
|
+
campfire = Tinder::Campfire.new(campfire_subdomain, :ssl => campfire_use_ssl)
|
24
|
+
unless campfire
|
25
|
+
log "Unable to establish connection to Campfire (#{campfire_subdomain}). Exiting."
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
log "Established connection to Campfire (#{campfire_subdomain})."
|
29
|
+
|
30
|
+
unless campfire.login(campfire_email, campfire_password)
|
31
|
+
log "Unable to log in to Campfire (#{campfire_subdomain}). Exiting."
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
log "Logged in to Campfire (#{campfire_subdomain})."
|
35
|
+
log "Available rooms: #{campfire.rooms.map(&:name).inspect}", :debug
|
36
|
+
|
37
|
+
@room = campfire.find_room_by_name campfire_room
|
38
|
+
if @room
|
39
|
+
log "Entered Campfire room '#{room.name}'."
|
40
|
+
else
|
41
|
+
log "No room '#{campfire_room}' found. Exiting."
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def run
|
47
|
+
last_statuses = initial_statuses
|
48
|
+
|
49
|
+
loop do
|
50
|
+
begin
|
51
|
+
new_statuses = []
|
52
|
+
checking_twitter_timelines do |user, status|
|
53
|
+
next if status.text == last_statuses[user]
|
54
|
+
new_statuses << status
|
55
|
+
last_statuses[user] = status.text
|
56
|
+
end
|
57
|
+
|
58
|
+
new_statuses.sort_by(&:created_at).each do |status|
|
59
|
+
begin
|
60
|
+
message = "[#{status.user.name}] #{status.text}"
|
61
|
+
log message
|
62
|
+
room.speak message
|
63
|
+
log "(Campfire updated)", :debug
|
64
|
+
rescue Timeout::Error => e
|
65
|
+
log "Campfire timeout: (#{e.message})"
|
66
|
+
ensure
|
67
|
+
sleep 2
|
68
|
+
end
|
69
|
+
end
|
70
|
+
rescue => e
|
71
|
+
log e.message
|
72
|
+
log e.backtrace
|
73
|
+
end
|
74
|
+
log "sleeping 10 seconds in main loop", :debug
|
75
|
+
sleep 10
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def verbose?
|
80
|
+
verbose
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def initial_statuses
|
86
|
+
returning statuses = {} do
|
87
|
+
checking_twitter_timelines do |user, status|
|
88
|
+
statuses[user] = status.text
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def checking_twitter_timelines
|
94
|
+
twitter_users.each do |user|
|
95
|
+
begin
|
96
|
+
log "Checking '#{user}' timeline...", :debug
|
97
|
+
twitter.timeline_for(:user, :id => user, :count => 1) do |status|
|
98
|
+
yield user, status
|
99
|
+
end
|
100
|
+
rescue Timeout::Error => e
|
101
|
+
log "Twitter timeout: (#{e.message})"
|
102
|
+
rescue Twitter::RESTError => e
|
103
|
+
log "Twitter REST Error: (#{e.message})"
|
104
|
+
ensure
|
105
|
+
log " ...done.", :debug
|
106
|
+
sleep 2
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def log(msg, level=:info)
|
112
|
+
if level == :info || (level == :debug && verbose?)
|
113
|
+
File.open(logfile || 'camptweet.log', 'wb') do |f|
|
114
|
+
f.puts "#{Time.now.strftime('%Y.%m.%d %H:%M:%S')} #{msg}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bdainton-camptweet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Dainton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: twitter4r
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.0
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: tinder
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.1.6
|
32
|
+
version:
|
33
|
+
description: A simple daemon that polls for updated Twitter statuses and posts them to a Campfire room.
|
34
|
+
email: brian.dainton@gmail.com
|
35
|
+
executables:
|
36
|
+
- camptweet
|
37
|
+
- camptweetd_base
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- bin/camptweet
|
44
|
+
- bin/camptweetd_base
|
45
|
+
- CHANGELOG
|
46
|
+
- init.rb
|
47
|
+
- lib/camptweet/bot.rb
|
48
|
+
- lib/camptweet.rb
|
49
|
+
- LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Manifest
|
52
|
+
- camptweet.gemspec
|
53
|
+
has_rdoc: false
|
54
|
+
homepage: http://github.com/bdainton/camptweet
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.0.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 2
|
78
|
+
summary: A simple daemon that polls for updated Twitter statuses and posts them to a Campfire room.
|
79
|
+
test_files: []
|
80
|
+
|