eastmedia-cinder 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +25 -0
- data/MIT-LICENSE +19 -0
- data/Manifest.txt +8 -0
- data/README.txt +55 -0
- data/Rakefile +12 -0
- data/lib/cinder.rb +13 -0
- data/lib/cinder/campfire.rb +182 -0
- metadata +89 -0
data/History.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
=== 0.1.0 / 2008-06-16
|
2
|
+
|
3
|
+
* Initial release. Provides support for single-day exporting.
|
4
|
+
|
5
|
+
=== 0.2.0 / 2008-06-16
|
6
|
+
|
7
|
+
* Minor release. Provides support for multi-day exporting to a specified directory.
|
8
|
+
|
9
|
+
=== 0.2.1 / 2008-06-16
|
10
|
+
|
11
|
+
* Bug fix. Removed explicit require of hpricot by cinder. Default retrieve_transcript to today.
|
12
|
+
|
13
|
+
=== 0.2.2 / 2008-06-16
|
14
|
+
|
15
|
+
* Tiny release. Provides support for retrieving all transcripts in a single room.
|
16
|
+
* Bug fix. Fixed logic problem that was excluding the current date when calling retrieve_transcripts_since.
|
17
|
+
|
18
|
+
=== 0.3.0 / 2008-06-16
|
19
|
+
|
20
|
+
* Minor release. Provides support form single, multi, and all-day exporting to a specific directory across all rooms in a Campfire account
|
21
|
+
* Bug fix. Replaces spaces in room names with underscores during file save.
|
22
|
+
|
23
|
+
=== 0.3.1 / 2008-06-16
|
24
|
+
|
25
|
+
* Tiny release. Provides the date column in the CSV file in universal date format mm/dd/yyyy.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 Matt Pelletier, Eastmedia (http://eastmedia.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= cinder - Export Campfire transcripts into CSVs
|
2
|
+
|
3
|
+
http://github.com/eastmedia/cinder
|
4
|
+
|
5
|
+
* mailto:matt@eastmedia.com
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
Cinder is a Ruby library for exporting transcripts from Campfire into CSV files.
|
10
|
+
|
11
|
+
== REQUIREMENTS:
|
12
|
+
|
13
|
+
* Ruby >= 1.8.6
|
14
|
+
* Mechanize gem
|
15
|
+
|
16
|
+
== INSTALL:
|
17
|
+
|
18
|
+
$ gem sources -a http://gems.github.com/ (you only need to do this once)
|
19
|
+
$ gem install eastmedia-cinder
|
20
|
+
|
21
|
+
== SOURCE:
|
22
|
+
|
23
|
+
Cinders's git repo is available on GitHub, which can be browsed at:
|
24
|
+
|
25
|
+
http://github.com/eastmedia/cinder
|
26
|
+
|
27
|
+
and cloned from:
|
28
|
+
|
29
|
+
git://github.com/eastmedia/cinder.git
|
30
|
+
|
31
|
+
|
32
|
+
From IRB or any script you write:
|
33
|
+
|
34
|
+
require "cinder"
|
35
|
+
|
36
|
+
campfire = Cinder::Campfire.new 'mysubdomain', :ssl => true
|
37
|
+
campfire.login 'myemail@example.com', 'mypassword'
|
38
|
+
campfire.set_room 'Room Name'
|
39
|
+
campfire.retrieve_transcript <date>
|
40
|
+
campfire.retrieve_transcripts_since <date>
|
41
|
+
campfire.retrieve_transcripts_between <start_date> <end_date>
|
42
|
+
|
43
|
+
== CREDITS:
|
44
|
+
|
45
|
+
Thanks to the folks behind the tinder gem.
|
46
|
+
Initial code by Mike Bueti at Eastmedia.
|
47
|
+
|
48
|
+
== HISTORY:
|
49
|
+
|
50
|
+
See History.txt in this directory.
|
51
|
+
|
52
|
+
== LICENSE:
|
53
|
+
|
54
|
+
Copyright (c) 2008 Eastmedia (http://eastmedia.com)
|
55
|
+
See MIT-LICENSE in this directory.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require './lib/cinder.rb'
|
4
|
+
|
5
|
+
Hoe.new('cinder', Cinder::VERSION) do |p|
|
6
|
+
p.summary = "Export Campfire transcripts into CSVs"
|
7
|
+
p.description = "Cinder is a Ruby library for exporting transcripts from Campfire into CSV files."
|
8
|
+
p.author = "Mike Bueti"
|
9
|
+
p.email = "matt@eastmedia.com"
|
10
|
+
p.url = 'http://github.com/eastmedia/cinder'
|
11
|
+
p.extra_deps << ['mechanize'] << ['colored']
|
12
|
+
end
|
data/lib/cinder.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'uri'
|
3
|
+
require 'mechanize'
|
4
|
+
require 'csv'
|
5
|
+
require 'colored'
|
6
|
+
|
7
|
+
Dir[File.join(File.dirname(__FILE__), 'cinder/**/*.rb')].sort.each { |lib| require lib }
|
8
|
+
|
9
|
+
|
10
|
+
module Cinder
|
11
|
+
VERSION = '0.3.1'
|
12
|
+
class Error < StandardError; end
|
13
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
module Cinder
|
2
|
+
|
3
|
+
|
4
|
+
# == Usage
|
5
|
+
#
|
6
|
+
# campfire = Cinder::Campfire.new 'mysubdomain', :ssl => true
|
7
|
+
# campfire.login 'myemail@example.com', 'mypassword'
|
8
|
+
# campfire.set_room 'Room Name'
|
9
|
+
# campfire.retrieve_transcript date
|
10
|
+
class Campfire
|
11
|
+
attr_reader :subdomain, :uri, :room, :directory
|
12
|
+
|
13
|
+
# Create a new connection to a campfire account with the given +subdomain+.
|
14
|
+
# There's an +:ssl+ option to use SSL for the connection.
|
15
|
+
#
|
16
|
+
# campfire = Cinder::Campfire.new("my_subdomain", :ssl => true)
|
17
|
+
def initialize(subdomain, options = {})
|
18
|
+
options = { :ssl => false }.merge(options)
|
19
|
+
@subdomain = subdomain
|
20
|
+
@uri = URI.parse("#{options[:ssl] ? "https" : "http"}://#{subdomain}.campfirenow.com")
|
21
|
+
@room = nil
|
22
|
+
@directory = "."
|
23
|
+
@agent = WWW::Mechanize.new
|
24
|
+
@logged_in = false
|
25
|
+
end
|
26
|
+
|
27
|
+
# Log in to campfire using your +email+ and +password+
|
28
|
+
def login(email, password)
|
29
|
+
unless @agent.post("#{@uri.to_s}/login", "email_address" => email, "password" => password).uri == @uri
|
30
|
+
raise Error, "Campfire login failed"
|
31
|
+
end
|
32
|
+
@lobby = @agent.page
|
33
|
+
@rooms = get_rooms(@lobby)
|
34
|
+
@logged_in = true
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns true if currently logged in
|
38
|
+
def logged_in?
|
39
|
+
@logged_in == true
|
40
|
+
end
|
41
|
+
|
42
|
+
# Logs out of the campfire account
|
43
|
+
def logout
|
44
|
+
if @agent.get("#{@uri}/logout").uri == URI.parse("#{@uri.to_s}/login")
|
45
|
+
@logged_in = false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Selects the room with name +room_name+ to retrieve transcripts from
|
50
|
+
def set_room(room_name)
|
51
|
+
@room = find_room_by_name(room_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set the directory where Cinder saves transcripts to +path+,
|
55
|
+
def set_directory(path)
|
56
|
+
if File.exists? path and File.directory? path
|
57
|
+
@directory = path.reverse.index("/") == 0 ? path.chop : path
|
58
|
+
else
|
59
|
+
raise Error, "Invalid path name"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Retrieve the transcript for the current room and +date+, passed in as a Time object, and store it locally as a csv file in the preselected directory, or the current location if no directory was set
|
64
|
+
def retrieve_transcript(date = Time.now)
|
65
|
+
transcript_uri = URI.parse("#{@room[:uri].to_s}/transcript/#{date.strftime("%Y/%m/%d")}")
|
66
|
+
transcript_page = @agent.get(transcript_uri.to_s)
|
67
|
+
transcript = transcript_page.parser
|
68
|
+
write_transcript(transcript, "#{@directory}/#{@room[:name].gsub(" ", "_")}_#{date.strftime("%m_%d_%Y")}", date)
|
69
|
+
rescue WWW::Mechanize::ResponseCodeError
|
70
|
+
end
|
71
|
+
|
72
|
+
# Retrieve all of the transcripts for the current room
|
73
|
+
def retrieve_all_transcripts
|
74
|
+
list_page = @agent.get("#{@uri}/files+transcripts?room_id=#{@room[:uri].to_s.split("/").last}")
|
75
|
+
while list_page.links.detect { |link| link.text == "Older" }
|
76
|
+
list_page.links.detect { |link| link.text == "Older" }.click
|
77
|
+
list_page = @agent.page
|
78
|
+
end
|
79
|
+
links = list_page.links
|
80
|
+
links.pop
|
81
|
+
earliest = links.pop.uri.to_s.split("/")
|
82
|
+
day = earliest.pop
|
83
|
+
month = earliest.pop
|
84
|
+
year = earliest.pop
|
85
|
+
retrieve_transcripts_since Time.mktime(year.to_i, month.to_i, day.to_i)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Retrieve the transcripts for the current room from the +date+ passed in as a Time object, up until and including the current date
|
89
|
+
def retrieve_transcripts_since(date)
|
90
|
+
retrieve_transcripts_between(date, Time.now)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Retrieve the transcripts for the current room created between the +start_date+ and +end_date+ passed in as a Time objects
|
94
|
+
def retrieve_transcripts_between(start_date, end_date)
|
95
|
+
while start_date <= end_date
|
96
|
+
retrieve_transcript(start_date)
|
97
|
+
start_date = start_date + 24*60*60
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Retrieve the transcripts from all rooms in this Campfire account for the +date+ passed in as a Time object
|
102
|
+
def retrieve_transcripts_from_all_rooms(date = Time.now)
|
103
|
+
preset_room = @room
|
104
|
+
@rooms.each do |room|
|
105
|
+
@room = room
|
106
|
+
retrieve_transcript date
|
107
|
+
end
|
108
|
+
@room = preset_room
|
109
|
+
end
|
110
|
+
|
111
|
+
# Retrieve the transcripts from all rooms in this Campfire account created since the +date+ passed in as a Time object
|
112
|
+
def retrieve_transcripts_from_all_rooms_since(date)
|
113
|
+
retrieve_transcripts_from_all_rooms_between date, Time.now
|
114
|
+
end
|
115
|
+
|
116
|
+
# Retrieve the transcripts from all rooms in this Campfire account created between the +start_date+ and the +end_date+ passed in as a Time objects
|
117
|
+
def retrieve_transcripts_from_all_rooms_between(start_date, end_date)
|
118
|
+
preset_room = @room
|
119
|
+
@rooms.each do |room|
|
120
|
+
@room = room
|
121
|
+
retrieve_transcripts_between start_date, end_date
|
122
|
+
end
|
123
|
+
@room = preset_room
|
124
|
+
end
|
125
|
+
|
126
|
+
# Retrieve all of the transcripts created in all of the rooms in this Campfire account
|
127
|
+
def retrieve_all_transcripts_from_all_rooms
|
128
|
+
preset_room = @room
|
129
|
+
@rooms.each do |room|
|
130
|
+
@room = room
|
131
|
+
retrieve_all_transcripts
|
132
|
+
end
|
133
|
+
@room = preset_room
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
# Find all of the room names and associated urls on the provided +page+
|
139
|
+
def get_rooms(page)
|
140
|
+
page.links.collect { |link| { :name => link.to_s, :uri => link.uri } if link.uri.to_s["#{uri.to_s}/room"] }.reject { |room| room.nil? }
|
141
|
+
end
|
142
|
+
|
143
|
+
# Find the room name and uri hash that matches the provided +room_name+
|
144
|
+
def find_room_by_name(room_name)
|
145
|
+
@rooms.collect { |room| room if room[:name] == room_name }.reject { |room| room.nil? }.first
|
146
|
+
end
|
147
|
+
|
148
|
+
# Parse the provided +transcript+ hpricot document and write the contents to the .csv file +file_name+
|
149
|
+
def write_transcript(transcript, file_name, date)
|
150
|
+
writer = CSV.open("#{file_name}.csv", 'w')
|
151
|
+
writer << ["Date", "Time", "User", "Message"]
|
152
|
+
date = date.strftime("%m/%d/%Y")
|
153
|
+
time = nil
|
154
|
+
user = nil
|
155
|
+
(transcript%"tbody[@id='chat']").each_child do |row|
|
156
|
+
if row.class == Hpricot::Elem
|
157
|
+
row.each_child do |cell|
|
158
|
+
if cell.class == Hpricot::Elem
|
159
|
+
if cell.classes.include? "time"
|
160
|
+
if cell.containers.any?
|
161
|
+
time = cell.containers.first.html
|
162
|
+
else
|
163
|
+
time = cell.html
|
164
|
+
end
|
165
|
+
elsif cell.classes.include? "person"
|
166
|
+
if cell.containers.any?
|
167
|
+
user = cell.containers.first.html
|
168
|
+
else
|
169
|
+
user = cell.html
|
170
|
+
end
|
171
|
+
elsif cell.classes.include? "body"
|
172
|
+
writer << [date, time, user, cell.containers.first.html]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
writer.close
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eastmedia-cinder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Bueti
|
8
|
+
- Matt Pelletier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-06-17 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: mechanize
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: colored
|
27
|
+
version_requirement:
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: "0"
|
33
|
+
version:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: hoe
|
36
|
+
version_requirement:
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.5.3
|
42
|
+
version:
|
43
|
+
description: Cinder is a Ruby library for exporting transcripts from Campfire into CSV files.
|
44
|
+
email: matt@eastmedia.com
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- History.txt
|
51
|
+
- Manifest.txt
|
52
|
+
- README.txt
|
53
|
+
files:
|
54
|
+
- History.txt
|
55
|
+
- MIT-LICENSE
|
56
|
+
- Manifest.txt
|
57
|
+
- README.txt
|
58
|
+
- Rakefile
|
59
|
+
- lib/cinder.rb
|
60
|
+
- lib/cinder/campfire.rb
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/eastmedia/cinder
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --main
|
66
|
+
- README.txt
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: cinder
|
84
|
+
rubygems_version: 1.0.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 2
|
87
|
+
summary: Export Campfire transcripts into CSVs
|
88
|
+
test_files: []
|
89
|
+
|