colloquy_log_to_text 1.0.5 → 1.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/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
@@ -11,41 +11,55 @@ if argc < 1
11
11
  exit 1
12
12
  end
13
13
 
14
- if !ARGV[0].match(/\.colloquyTranscript$/)
15
- puts "Error: File is not a Colloquy log."
16
- exit 1
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
- f = File.open(ARGV[0])
20
- doc = Nokogiri::XML(f)
21
- f.close
22
- f = File.open(ARGV[0].gsub(".colloquyTranscript", ".txt"), "w")
23
- envelopes = doc.css("envelope")
24
- envelopes.each { |envelope|
25
- messages = envelope.css("message")
26
- messages.each { |message|
27
- @printed_message = message.content
28
- @timestamp_string = message.attr("received")
29
- @timestamp = DateTime.strptime(@timestamp_string, "%F %H:%M:%S")
30
- @is_action = message.attr("action")
31
- }
32
- senders = envelope.css("sender")
33
- senders.each { |sender|
34
- @nick = sender.content
35
- case sender.attr("class")
36
- when "voice"
37
- @class = "+"
38
- when "operator"
39
- @class = "@"
40
- when "founder"
41
- @class = "~"
42
- when "administrator"
43
- @class = "&"
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
- if @is_action == "yes"
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
@@ -10,41 +10,55 @@ if argc < 1
10
10
  exit 1
11
11
  end
12
12
 
13
- if !ARGV[0].match(/\.colloquyTranscript$/)
14
- puts "Error: File is not a Colloquy log."
15
- exit 1
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
- f = File.open(ARGV[0])
19
- doc = Nokogiri::XML(f)
20
- f.close
21
- f = File.open(ARGV[0].gsub(".colloquyTranscript", ".txt"), "w")
22
- envelopes = doc.css("envelope")
23
- envelopes.each { |envelope|
24
- messages = envelope.css("message")
25
- messages.each { |message|
26
- @printed_message = message.content
27
- @timestamp_string = message.attr("received")
28
- @timestamp = DateTime.strptime(@timestamp_string, "%F %H:%M:%S")
29
- @is_action = message.attr("action")
30
- }
31
- senders = envelope.css("sender")
32
- senders.each { |sender|
33
- @nick = sender.content
34
- case sender.attr("class")
35
- when "voice"
36
- @class = "+"
37
- when "operator"
38
- @class = "@"
39
- when "founder"
40
- @class = "~"
41
- when "administrator"
42
- @class = "&"
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
- if @is_action == "yes"
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.0.5
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