colloquy_log_to_text 1.0.5 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -0
- data/bin/colloquy_log_to_text +48 -34
- data/lib/colloquy_log_to_text.rb +48 -34
- metadata +2 -2
- data/README +0 -0
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
This is a simple ruby script to convert Colloquy's awful XML logs
|
2
|
+
(`.colloquyTranscript`) to plain text (`.txt`).
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
1. `gem install colloquy_log_to_text`
|
7
|
+
2. Done!
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
1. `colloquy_log_to_text log.colloquyTranscript`
|
12
|
+
2. Plain text log will be in the file named `log.txt`
|
13
|
+
|
14
|
+
## Development
|
15
|
+
|
16
|
+
1. Fork
|
17
|
+
1. Edit `lib/colloquy_log_to_text.rb`
|
18
|
+
2. `rake`
|
19
|
+
3. Submit pull request
|
data/bin/colloquy_log_to_text
CHANGED
@@ -11,41 +11,55 @@ if argc < 1
|
|
11
11
|
exit 1
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
for arg in ARGV
|
15
|
+
case arg
|
16
|
+
when "-h"
|
17
|
+
puts "Usage: colloquy_log_to_text [-h] <LOGFILE>"
|
18
|
+
puts "The log file specified (.colloquyTranscript) will then be converted into plain text."
|
19
|
+
puts "The -h option is used to display this help message."
|
20
|
+
exit 0
|
21
|
+
else
|
22
|
+
if !arg.match(/\.colloquyTranscript$/)
|
23
|
+
puts "Error: File is not a Colloquy log."
|
24
|
+
next
|
25
|
+
end
|
26
|
+
filenames.push arg
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
f.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
30
|
+
for file in filenames
|
31
|
+
puts "Converting #{file}..."
|
32
|
+
f = File.open(file)
|
33
|
+
doc = Nokogiri::XML(f)
|
34
|
+
f.close
|
35
|
+
f = File.open(file.gsub(".colloquyTranscript", ".txt"), "w")
|
36
|
+
envelopes = doc.css("envelope")
|
37
|
+
envelopes.each { |envelope|
|
38
|
+
messages = envelope.css("message")
|
39
|
+
messages.each { |message|
|
40
|
+
@printed_message = message.content
|
41
|
+
@timestamp_string = message.attr("received")
|
42
|
+
@timestamp = DateTime.strptime(@timestamp_string, "%F %H:%M:%S")
|
43
|
+
@is_action = message.attr("action")
|
44
|
+
}
|
45
|
+
senders = envelope.css("sender")
|
46
|
+
senders.each { |sender|
|
47
|
+
@nick = sender.content
|
48
|
+
case sender.attr("class")
|
49
|
+
when "voice"
|
50
|
+
@class = "+"
|
51
|
+
when "operator"
|
52
|
+
@class = "@"
|
53
|
+
when "founder"
|
54
|
+
@class = "~"
|
55
|
+
when "administrator"
|
56
|
+
@class = "&"
|
57
|
+
end
|
58
|
+
}
|
59
|
+
if @is_action == "yes"
|
60
|
+
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] * #{@nick} #{@printed_message}"
|
61
|
+
else
|
62
|
+
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] <#{@class}#{@nick}> #{@printed_message}"
|
44
63
|
end
|
45
64
|
}
|
46
|
-
|
47
|
-
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] * #{@nick} #{@printed_message}"
|
48
|
-
else
|
49
|
-
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] <#{@class}#{@nick}> #{@printed_message}"
|
50
|
-
end
|
51
|
-
}
|
65
|
+
end
|
data/lib/colloquy_log_to_text.rb
CHANGED
@@ -10,41 +10,55 @@ if argc < 1
|
|
10
10
|
exit 1
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
for arg in ARGV
|
14
|
+
case arg
|
15
|
+
when "-h"
|
16
|
+
puts "Usage: colloquy_log_to_text [-h] <LOGFILE>"
|
17
|
+
puts "The log file specified (.colloquyTranscript) will then be converted into plain text."
|
18
|
+
puts "The -h option is used to display this help message."
|
19
|
+
exit 0
|
20
|
+
else
|
21
|
+
if !arg.match(/\.colloquyTranscript$/)
|
22
|
+
puts "Error: File is not a Colloquy log."
|
23
|
+
next
|
24
|
+
end
|
25
|
+
filenames.push arg
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
f.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
for file in filenames
|
30
|
+
puts "Converting #{file}..."
|
31
|
+
f = File.open(file)
|
32
|
+
doc = Nokogiri::XML(f)
|
33
|
+
f.close
|
34
|
+
f = File.open(file.gsub(".colloquyTranscript", ".txt"), "w")
|
35
|
+
envelopes = doc.css("envelope")
|
36
|
+
envelopes.each { |envelope|
|
37
|
+
messages = envelope.css("message")
|
38
|
+
messages.each { |message|
|
39
|
+
@printed_message = message.content
|
40
|
+
@timestamp_string = message.attr("received")
|
41
|
+
@timestamp = DateTime.strptime(@timestamp_string, "%F %H:%M:%S")
|
42
|
+
@is_action = message.attr("action")
|
43
|
+
}
|
44
|
+
senders = envelope.css("sender")
|
45
|
+
senders.each { |sender|
|
46
|
+
@nick = sender.content
|
47
|
+
case sender.attr("class")
|
48
|
+
when "voice"
|
49
|
+
@class = "+"
|
50
|
+
when "operator"
|
51
|
+
@class = "@"
|
52
|
+
when "founder"
|
53
|
+
@class = "~"
|
54
|
+
when "administrator"
|
55
|
+
@class = "&"
|
56
|
+
end
|
57
|
+
}
|
58
|
+
if @is_action == "yes"
|
59
|
+
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] * #{@nick} #{@printed_message}"
|
60
|
+
else
|
61
|
+
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] <#{@class}#{@nick}> #{@printed_message}"
|
43
62
|
end
|
44
63
|
}
|
45
|
-
|
46
|
-
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] * #{@nick} #{@printed_message}"
|
47
|
-
else
|
48
|
-
f.puts "[#{@timestamp.day}-#{@timestamp.month}-#{@timestamp.year} #{@timestamp.hour}:#{@timestamp.minute}] <#{@class}#{@nick}> #{@printed_message}"
|
49
|
-
end
|
50
|
-
}
|
64
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: colloquy_log_to_text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: "1.1"
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mark Szymanski
|
@@ -23,7 +23,7 @@ extensions: []
|
|
23
23
|
extra_rdoc_files: []
|
24
24
|
|
25
25
|
files:
|
26
|
-
- README
|
26
|
+
- README.md
|
27
27
|
- lib/colloquy_log_to_text.rb
|
28
28
|
- bin/colloquy_log_to_text
|
29
29
|
has_rdoc: true
|
data/README
DELETED
File without changes
|