irc-log-parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/irc-log-parser.gemspec +23 -0
- data/lib/irc-log-parser.rb +10 -0
- data/lib/irc-log-parser/log.rb +44 -0
- data/lib/irc-log-parser/logs.rb +60 -0
- data/lib/irc-log-parser/parse_exception.rb +4 -0
- data/lib/irc-log-parser/tiarra.rb +21 -0
- data/lib/irc-log-parser/version.rb +3 -0
- data/lib/irc-log-parser/znc.rb +20 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8b1efa2ba5c85054d01cd96c4b239b4011b5d3a
|
4
|
+
data.tar.gz: eeb24a063c2983c38390ba8987d6f16cde75f520
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fcb9f8c4d59686a3f143a7c2889fa3fc2b2b8772182997a13efe298653f397395799c282e6fd2e7d74037081b488f5c3e845222b9b0ee3663cb49c11bbd8c7f
|
7
|
+
data.tar.gz: 7d03f2858d79caa696007ed9ba5c827f1fa16f4c78ba830458e1ef51da99aeccbabc48d3585affc7f103ec0579cbbae8b6643a021fed4f7479ec13d426c7d6bb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 shunirr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# IrcLogParser
|
2
|
+
|
3
|
+
IrcLogParser is parsing tiarra and znc log.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'irc-log-parser'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install irc-log-parser
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'irc-log-parser'
|
23
|
+
```
|
24
|
+
|
25
|
+
Parse your IRC logs.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# tiarra
|
29
|
+
logs = IrcLogParser::Logs.new(:tiarra, '~/tiarra/logs/#channel@network/2014.01.01.txt')
|
30
|
+
|
31
|
+
# znc
|
32
|
+
logs = IrcLogParser::Logs.new(:znc, "~/.znc/moddata/log/shunirr_network_\#channel_20140101.log")
|
33
|
+
```
|
34
|
+
|
35
|
+
Export to JSON and LTSV.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
logs[0].to_json
|
39
|
+
# => "{\"network\":\"network\",\"channel\":\"#channel\",\"time\":\"2014-01-01 00:00:00 +0900\",\"nick\":\"shunirr\",\"text\":\"Hello world\",\"is_notice\":false}"
|
40
|
+
|
41
|
+
logs[0].to_ltsv
|
42
|
+
# => "network:network\tchannel:#channel\ttime:2014-01-01 00:00:00 +0900\tnick:shunirr\ttext:Hello world\tis_notice:false\t"
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'irc-log-parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "irc-log-parser"
|
8
|
+
spec.version = IrcLogParser::VERSION
|
9
|
+
spec.authors = ["shunirr"]
|
10
|
+
spec.email = ["m@s5r.jp"]
|
11
|
+
spec.description = %q{IrcLogParser is parsing tiarra and znc log.}
|
12
|
+
spec.summary = %q{IrcLogParser is parsing tiarra and znc log.}
|
13
|
+
spec.homepage = "https://github.com/shunirr/irc-log-parser-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "irc-log-parser/version"
|
2
|
+
|
3
|
+
module IrcLogParser
|
4
|
+
autoload :Log, 'irc-log-parser/log'
|
5
|
+
autoload :Logs, 'irc-log-parser/logs'
|
6
|
+
autoload :Tiarra, 'irc-log-parser/tiarra'
|
7
|
+
autoload :Znc, 'irc-log-parser/znc'
|
8
|
+
autoload :ParseException, 'irc-log-parser/parse_exception'
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module IrcLogParser
|
4
|
+
class Log
|
5
|
+
attr :network, :channel, :time, :nick, :text, :is_notice
|
6
|
+
|
7
|
+
def initialize(args = {})
|
8
|
+
@network = args[:network]
|
9
|
+
@channel = args[:channel]
|
10
|
+
@time = args[:time]
|
11
|
+
@nick = args[:nick]
|
12
|
+
@text = args[:text]
|
13
|
+
@is_notice = args[:is_notice]
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse
|
17
|
+
"not implement"
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_ltsv
|
21
|
+
"network:#{@network}\t" +
|
22
|
+
"channel:#{@channel}\t" +
|
23
|
+
"time:#{@time}\t" +
|
24
|
+
"nick:#{@nick}\t" +
|
25
|
+
"text:#{@text}\t" +
|
26
|
+
"is_notice:#{@is_notice}\t"
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_json(*args)
|
30
|
+
JSON.generate({
|
31
|
+
network: @network,
|
32
|
+
channel: @channel,
|
33
|
+
time: @time,
|
34
|
+
nick: @nick,
|
35
|
+
text: @text,
|
36
|
+
is_notice: @is_notice,
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
to_json.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module IrcLogParser
|
5
|
+
class Logs < Array
|
6
|
+
def initialize(type, path)
|
7
|
+
@type = type
|
8
|
+
@path = File.expand_path path
|
9
|
+
load_file
|
10
|
+
parse_path
|
11
|
+
parse_logs
|
12
|
+
end
|
13
|
+
|
14
|
+
# def to_json
|
15
|
+
# JSON.generate self
|
16
|
+
# end
|
17
|
+
|
18
|
+
private
|
19
|
+
def parse_logs
|
20
|
+
@logs.each do |log|
|
21
|
+
begin
|
22
|
+
self << parse(log)
|
23
|
+
rescue ParseException => e
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_file
|
29
|
+
file = open(@path).read
|
30
|
+
file.encode "UTF-16BE", "UTF-8", invalid: :replace, undef: :replace, replace: '.'
|
31
|
+
file.encode "UTF-8"
|
32
|
+
@logs = file.split /(\n|\r|\r\n)/
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_path
|
36
|
+
filename = File.basename(@path).gsub(/\.\w+$/, '')
|
37
|
+
dirname = File.dirname(@path).split('/').last
|
38
|
+
case @type
|
39
|
+
when :tiarra
|
40
|
+
@network = dirname.split('@').last
|
41
|
+
@date = Date.parse filename
|
42
|
+
when :znc
|
43
|
+
if /^\w+_(\w+)_(#?\w+)_(\d+)$/ =~ filename
|
44
|
+
@network = $1
|
45
|
+
@channel = $2
|
46
|
+
@date = Date.parse $3
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse(line)
|
52
|
+
case @type
|
53
|
+
when :tiarra
|
54
|
+
Tiarra.parse @network, @date, line
|
55
|
+
when :znc
|
56
|
+
Znc.parse @network, @channel, @date, line
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module IrcLogParser
|
2
|
+
class Tiarra < Log
|
3
|
+
def self.parse(network, date, line)
|
4
|
+
is_notice = false
|
5
|
+
if line =~ /^(\d\d):(\d\d):(\d\d) <(#[^:]+?):([^>]+)> (.*)$/
|
6
|
+
is_notice = false
|
7
|
+
elsif line =~ /^(\d\d):(\d\d):(\d\d) \((#[^:]+?):([^)]+)\) (.*)$/
|
8
|
+
is_notice = true
|
9
|
+
end
|
10
|
+
time = Time.local date.year, date.mon, date.mday, $1.to_i, $2.to_i, $3.to_i
|
11
|
+
channel = $4
|
12
|
+
nick = $5
|
13
|
+
text = $6
|
14
|
+
if network and channel and text and time and nick
|
15
|
+
new(network:network, channel:channel, text:text, time:time, nick:nick, is_notice:is_notice)
|
16
|
+
else
|
17
|
+
raise ParseException.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module IrcLogParser
|
2
|
+
class Znc < Log
|
3
|
+
def self.parse(network, channel, date, line)
|
4
|
+
is_notice = false
|
5
|
+
if line =~ /^\[(\d+):(\d+):(\d+)\] <([^>]*)> (.*)$/
|
6
|
+
is_notice = false
|
7
|
+
elsif line =~ /^\[(\d+):(\d+):(\d+)\] -(.*)- (.*)$/
|
8
|
+
is_notice = true
|
9
|
+
end
|
10
|
+
time = Time.local date.year, date.mon, date.mday, $1.to_i, $2.to_i, $3.to_i
|
11
|
+
nick = $4
|
12
|
+
text = $5
|
13
|
+
if network and channel and text and time and nick
|
14
|
+
new(network:network, channel:channel, text:text, time:time, nick:nick, is_notice:is_notice)
|
15
|
+
else
|
16
|
+
raise ParseException.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: irc-log-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shunirr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: IrcLogParser is parsing tiarra and znc log.
|
42
|
+
email:
|
43
|
+
- m@s5r.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- irc-log-parser.gemspec
|
54
|
+
- lib/irc-log-parser.rb
|
55
|
+
- lib/irc-log-parser/log.rb
|
56
|
+
- lib/irc-log-parser/logs.rb
|
57
|
+
- lib/irc-log-parser/parse_exception.rb
|
58
|
+
- lib/irc-log-parser/tiarra.rb
|
59
|
+
- lib/irc-log-parser/version.rb
|
60
|
+
- lib/irc-log-parser/znc.rb
|
61
|
+
homepage: https://github.com/shunirr/irc-log-parser-ruby
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
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
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: IrcLogParser is parsing tiarra and znc log.
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|