fluent-plugin-mixi_community 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/LICENSE +7 -0
- data/README.md +57 -0
- data/Rakefile +8 -0
- data/fluent-plugin-mixi_community.gemspec +17 -0
- data/lib/fluent/plugin/in_mixi_community.rb +96 -0
- metadata +100 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 todesking
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# fluent-plugin-mixi_community
|
2
|
+
|
3
|
+
Fluentd input plugin from Mixi community.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fluent-plugin-mixi_community'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fluent-plugin-mixi_community
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
# fluent.conf
|
22
|
+
<source>
|
23
|
+
type mixi_community
|
24
|
+
|
25
|
+
tag mixi
|
26
|
+
|
27
|
+
community_id 12345
|
28
|
+
|
29
|
+
# Regexp for thread title
|
30
|
+
thread_title_pattern 雑談|要望
|
31
|
+
# Top N threads to watch
|
32
|
+
recent_threads_num 4
|
33
|
+
|
34
|
+
# optional, default=true
|
35
|
+
# omit output when startup
|
36
|
+
silent_startup true
|
37
|
+
|
38
|
+
# Pit ID for Mixi account('email' and 'password' required)
|
39
|
+
pit_id mixi
|
40
|
+
|
41
|
+
# Update interval[sec]
|
42
|
+
interval_sec 20
|
43
|
+
</source>
|
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 'Added some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
52
|
+
|
53
|
+
## Changes
|
54
|
+
|
55
|
+
### 0.0.1
|
56
|
+
|
57
|
+
* Initial release.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "fluent-plugin-mixi_community"
|
3
|
+
gem.version = "0.0.1"
|
4
|
+
gem.authors = ["todesking"]
|
5
|
+
gem.email = ["discommunicative@gmail.com"]
|
6
|
+
gem.summary = %q{Fluentd input plugin, source from Mixi community}
|
7
|
+
gem.homepage = "https://github.com/todesking/fluent-plugin-mixi_community"
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split($\)
|
10
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
|
14
|
+
gem.add_runtime_dependency "mixi-community"
|
15
|
+
gem.add_runtime_dependency "fluentd"
|
16
|
+
gem.add_runtime_dependency "pit"
|
17
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'fluent/plugin'
|
2
|
+
require 'fluent/config'
|
3
|
+
require 'fluent/input'
|
4
|
+
|
5
|
+
1.tap do
|
6
|
+
# https://github.com/fluent/fluentd/issues/76
|
7
|
+
encoding = Encoding.default_internal
|
8
|
+
Encoding.default_internal = nil
|
9
|
+
require 'mime/types'
|
10
|
+
Encoding.default_internal = encoding
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'mixi-community'
|
14
|
+
require 'pit'
|
15
|
+
|
16
|
+
class Fluent::MixiCommunityInput < Fluent::Input
|
17
|
+
Fluent::Plugin.register_input('mixi_community', self)
|
18
|
+
|
19
|
+
config_param :interval_sec, :integer
|
20
|
+
config_param :pit_id, :string
|
21
|
+
config_param :community_id, :integer
|
22
|
+
config_param :thread_title_pattern, :string
|
23
|
+
config_param :recent_threads_num, :integer
|
24
|
+
config_param :tag, :string
|
25
|
+
config_param :silent_startup, :bool, default: true
|
26
|
+
|
27
|
+
def configure(config)
|
28
|
+
super
|
29
|
+
@thread_title_pattern = Regexp.new(@thread_title_pattern, {}, 'n')
|
30
|
+
|
31
|
+
user_info = Pit.get(@pit_id, require: {
|
32
|
+
'email' => 'mail',
|
33
|
+
'password' => 'password',
|
34
|
+
})
|
35
|
+
@fetcher = Mixi::Community::Fetcher.new(
|
36
|
+
user_info['email'],
|
37
|
+
user_info['password']
|
38
|
+
)
|
39
|
+
@community = Mixi::Community.new(@community_id)
|
40
|
+
# {[community_id, bbs_id] => last_comment_id}
|
41
|
+
@last_comment_ids = {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def start
|
45
|
+
@thread = Thread.new(&method(:run))
|
46
|
+
end
|
47
|
+
|
48
|
+
def shutdown
|
49
|
+
@thread.kill
|
50
|
+
end
|
51
|
+
|
52
|
+
def run
|
53
|
+
@first_time = true
|
54
|
+
loop do
|
55
|
+
begin
|
56
|
+
fetch_and_emit
|
57
|
+
rescue StandardError, Timeout::Error
|
58
|
+
$log.error("mixi_community(community_id=#{@community_id}): #{$!.inspect}")
|
59
|
+
$log.error_backtrace
|
60
|
+
end
|
61
|
+
@first_time = false
|
62
|
+
sleep @interval_sec
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def fetch_and_emit
|
67
|
+
@community.fetch(@fetcher)
|
68
|
+
@community.recent_bbses[0...@recent_threads_num].select{|th| th.title =~ @thread_title_pattern}.each do|th|
|
69
|
+
sleep 1
|
70
|
+
th.fetch(@fetcher)
|
71
|
+
th.recent_comments.each do|comment|
|
72
|
+
last_comment_id = @last_comment_ids[[@community.id, th.id]]
|
73
|
+
next if last_comment_id && comment.id <= last_comment_id
|
74
|
+
@last_comment_ids[[@community.id, th.id]] = comment.id
|
75
|
+
|
76
|
+
next if @silent_startup && @first_time
|
77
|
+
|
78
|
+
Fluent::Engine.emit(@tag, Fluent::Engine.now, {
|
79
|
+
'community' => {
|
80
|
+
'id' => @community.id,
|
81
|
+
},
|
82
|
+
'thread' => {
|
83
|
+
'id' => th.id,
|
84
|
+
'title' => th.title,
|
85
|
+
},
|
86
|
+
'comment' => {
|
87
|
+
'id' => comment.id,
|
88
|
+
'num' => comment.num,
|
89
|
+
'user_name' => comment.user_name,
|
90
|
+
'body_text' => comment.body_text,
|
91
|
+
}
|
92
|
+
})
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-mixi_community
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- todesking
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mixi-community
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fluentd
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pit
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description:
|
63
|
+
email:
|
64
|
+
- discommunicative@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- fluent-plugin-mixi_community.gemspec
|
75
|
+
- lib/fluent/plugin/in_mixi_community.rb
|
76
|
+
homepage: https://github.com/todesking/fluent-plugin-mixi_community
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.24
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Fluentd input plugin, source from Mixi community
|
100
|
+
test_files: []
|