fluent-plugin-twitter 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -16
- data/README.md +51 -6
- data/fluent-plugin-twitter.gemspec +4 -2
- data/lib/fluent/plugin/in_twitter.rb +94 -0
- data/test/helper.rb +1 -0
- data/test/plugin/test_in_twitter.rb +40 -0
- data/test/plugin/test_out_twitter.rb +6 -6
- metadata +33 -8
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
fluent-plugin-twitter
|
2
2
|
=====================
|
3
3
|
|
4
|
-
##
|
5
|
-
create your own
|
4
|
+
## Component
|
5
|
+
Fluentd Input/Output plugin. You can create your own "Twitter Bot" with fluentd messaging system.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -17,22 +17,67 @@ gem install fluent-plugin-twitter
|
|
17
17
|
/usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-twitter
|
18
18
|
`````
|
19
19
|
|
20
|
-
## Configuration
|
20
|
+
## Input Configuration
|
21
21
|
|
22
|
-
### Sample
|
22
|
+
### Input Sample
|
23
23
|
`````
|
24
|
+
<source>
|
25
|
+
type twitter
|
26
|
+
consumer_key YOUR_CONSUMER_KEY # Required
|
27
|
+
consumer_secret YOUR_CONSUMER_SECRET # Required
|
28
|
+
oauth_token YOUR_OAUTH_TOKEN # Required
|
29
|
+
oauth_token_secret YOUR_OAUTH_TOKEN_SECRET # Required
|
30
|
+
tag input.twitter.sampling # Required
|
31
|
+
timeline sampling # Required (sampling or userstream)
|
32
|
+
keyword Ruby,Python # Optional (userstream not supported yet)
|
33
|
+
lang ja,en # Optional
|
34
|
+
</source>
|
35
|
+
|
36
|
+
<match input.twitter.sampling>
|
37
|
+
type stdout
|
38
|
+
</match>
|
39
|
+
`````
|
40
|
+
|
41
|
+
### Debug
|
42
|
+
`````
|
43
|
+
$ tail -f /var/log/td-agent/td-agent.log
|
44
|
+
`````
|
45
|
+
|
46
|
+
## Output Configuration
|
47
|
+
|
48
|
+
### Output Sample
|
49
|
+
`````
|
50
|
+
<source>
|
51
|
+
type http
|
52
|
+
port 8888
|
53
|
+
</source>
|
54
|
+
|
24
55
|
<match notify.twitter>
|
25
56
|
type twitter
|
26
57
|
consumer_key YOUR_CONSUMER_KEY
|
27
58
|
consumer_secret YOUR_CONSUMER_SECRET
|
28
|
-
oauth_token
|
29
|
-
oauth_token_secret
|
59
|
+
oauth_token YOUR_OAUTH_TOKEN
|
60
|
+
oauth_token_secret YOUR_OAUTH_TOKEN_SECRET
|
30
61
|
</match>
|
31
62
|
`````
|
32
63
|
|
64
|
+
### Debug
|
65
|
+
`````
|
66
|
+
$ curl http://localhost:8888/notify.twitter -F 'json={"message":"foo"}'
|
67
|
+
`````
|
68
|
+
|
69
|
+
## Reference
|
70
|
+
|
71
|
+
### Twitter OAuth Guide
|
72
|
+
http://pocketstudio.jp/log3/2012/02/12/how_to_get_twitter_apikey_and_token/
|
73
|
+
|
33
74
|
## TODO
|
34
75
|
patches welcome!
|
35
76
|
|
77
|
+
## Known Issue
|
78
|
+
On starting fluentd, appearing alert message below. Please tell me how to fix up.
|
79
|
+
`/usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:1530: warning: already initialized constant EM`
|
80
|
+
|
36
81
|
## Copyright
|
37
82
|
|
38
83
|
Copyright © 2012- Kentaro Yoshida (@yoshi_ken)
|
@@ -3,11 +3,11 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-twitter"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.1.1"
|
7
7
|
s.authors = ["Kentaro Yoshida"]
|
8
8
|
s.email = ["y.ken.studio@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/y-ken/fluent-plugin-twitter"
|
10
|
-
s.summary = %q{Fluentd Output
|
10
|
+
s.summary = %q{Fluentd Input/Output plugin. You can create your own "Twitter Bot" with fluentd messaging system.}
|
11
11
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
13
13
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
# specify any dependencies here; for example:
|
18
18
|
s.add_development_dependency "fluentd"
|
19
19
|
s.add_runtime_dependency "fluentd"
|
20
|
+
s.add_runtime_dependency "twitter"
|
21
|
+
s.add_runtime_dependency "tweetstream"
|
20
22
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Fluent
|
2
|
+
class TwitterInput < Fluent::Input
|
3
|
+
TIMELINE_TYPE = %w(userstream sampling)
|
4
|
+
Plugin.register_input('twitter', self)
|
5
|
+
|
6
|
+
config_param :consumer_key, :string
|
7
|
+
config_param :consumer_secret, :string
|
8
|
+
config_param :oauth_token, :string
|
9
|
+
config_param :oauth_token_secret, :string
|
10
|
+
config_param :tag, :string
|
11
|
+
config_param :timeline, :string
|
12
|
+
config_param :keyword, :string, :default => nil
|
13
|
+
config_param :lang, :string, :default => ''
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
require 'tweetstream'
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
raise Fluent::ConfigError, "timeline value undefined #{@timeline}" if !TIMELINE_TYPE.include?(@timeline)
|
23
|
+
TweetStream.configure do |config|
|
24
|
+
config.consumer_key = @consumer_key
|
25
|
+
config.consumer_secret = @consumer_secret
|
26
|
+
config.oauth_token = @oauth_token
|
27
|
+
config.oauth_token_secret = @oauth_token_secret
|
28
|
+
config.auth_method = :oauth
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def start
|
33
|
+
@thread = Thread.new(&method(:run))
|
34
|
+
end
|
35
|
+
|
36
|
+
def shutdown
|
37
|
+
Thread.kill(@thread)
|
38
|
+
end
|
39
|
+
|
40
|
+
def run
|
41
|
+
if @timeline == 'sampling' && @keyword
|
42
|
+
start_twitter_track
|
43
|
+
elsif @timeline == 'sampling' && @keyword.nil?
|
44
|
+
start_twitter_sample
|
45
|
+
elsif @timeline == 'userstream'
|
46
|
+
start_twitter_userstream
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def start_twitter_track
|
51
|
+
$log.info "starting twitter keyword tracking. tag:#{@tag} lang:#{@lang} keyword:#{@keyword}"
|
52
|
+
client = TweetStream::Client.new
|
53
|
+
client.track(@keyword) do |status|
|
54
|
+
next unless status.text
|
55
|
+
next unless @lang.include?(status.user.lang)
|
56
|
+
get_message(status)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def start_twitter_sample
|
61
|
+
$log.info "starting twitter sampled streaming. tag:#{@tag} lang:#{@lang}"
|
62
|
+
client = TweetStream::Client.new
|
63
|
+
client.sample do |status|
|
64
|
+
next unless status.text
|
65
|
+
next unless @lang.include?(status.user.lang)
|
66
|
+
get_message(status)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def start_twitter_userstream
|
71
|
+
$log.info "starting twitter userstream tracking. tag:#{@tag} lang:#{@lang}"
|
72
|
+
client = TweetStream::Client.new
|
73
|
+
client.userstream do |status|
|
74
|
+
next unless status.text
|
75
|
+
next unless @lang.include?(status.user.lang)
|
76
|
+
get_message(status)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_message(status)
|
81
|
+
record = Hash.new
|
82
|
+
record.store('message', status.text)
|
83
|
+
record.store('geo', status.geo)
|
84
|
+
record.store('place', status.place)
|
85
|
+
record.store('created_at', status.created_at)
|
86
|
+
record.store('user_name', status.user.name)
|
87
|
+
record.store('user_screen_name', status.user.screen_name)
|
88
|
+
record.store('user_profile_image_url', status.user.profile_image_url)
|
89
|
+
record.store('user_time_zone', status.user.time_zone)
|
90
|
+
record.store('user_lang', status.user.lang)
|
91
|
+
Engine.emit(@tag, Engine.now, record)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TwitterInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
consumer_key CONSUMER_KEY
|
10
|
+
consumer_secret CONSUMER_SECRET
|
11
|
+
oauth_token OAUTH_TOKEN
|
12
|
+
oauth_token_secret OAUTH_TOKEN_SECRET
|
13
|
+
tag input.twitter
|
14
|
+
timeline sampling
|
15
|
+
]
|
16
|
+
|
17
|
+
def create_driver(conf=CONFIG,tag='test')
|
18
|
+
Fluent::Test::OutputTestDriver.new(Fluent::TwitterInput, tag).configure(conf)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_configure
|
22
|
+
assert_raise(Fluent::ConfigError) {
|
23
|
+
d = create_driver('')
|
24
|
+
}
|
25
|
+
d = create_driver %[
|
26
|
+
consumer_key CONSUMER_KEY
|
27
|
+
consumer_secret CONSUMER_SECRET
|
28
|
+
oauth_token OAUTH_TOKEN
|
29
|
+
oauth_token_secret OAUTH_TOKEN_SECRET
|
30
|
+
tag input.twitter
|
31
|
+
timeline sampling
|
32
|
+
]
|
33
|
+
d.instance.inspect
|
34
|
+
assert_equal 'CONSUMER_KEY', d.instance.consumer_key
|
35
|
+
assert_equal 'CONSUMER_SECRET', d.instance.consumer_secret
|
36
|
+
assert_equal 'OAUTH_TOKEN', d.instance.oauth_token
|
37
|
+
assert_equal 'OAUTH_TOKEN_SECRET', d.instance.oauth_token_secret
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -8,8 +8,8 @@ class TwitterOutputTest < Test::Unit::TestCase
|
|
8
8
|
CONFIG = %[
|
9
9
|
consumer_key CONSUMER_KEY
|
10
10
|
consumer_secret CONSUMER_SECRET
|
11
|
-
oauth_token
|
12
|
-
oauth_token_secret
|
11
|
+
oauth_token OAUTH_TOKEN
|
12
|
+
oauth_token_secret OAUTH_TOKEN_SECRET
|
13
13
|
]
|
14
14
|
|
15
15
|
def create_driver(conf=CONFIG,tag='test')
|
@@ -23,14 +23,14 @@ class TwitterOutputTest < Test::Unit::TestCase
|
|
23
23
|
d = create_driver %[
|
24
24
|
consumer_key CONSUMER_KEY
|
25
25
|
consumer_secret CONSUMER_SECRET
|
26
|
-
oauth_token
|
27
|
-
oauth_token_secret
|
26
|
+
oauth_token OAUTH_TOKEN
|
27
|
+
oauth_token_secret OAUTH_TOKEN_SECRET
|
28
28
|
]
|
29
29
|
d.instance.inspect
|
30
30
|
assert_equal 'CONSUMER_KEY', d.instance.consumer_key
|
31
31
|
assert_equal 'CONSUMER_SECRET', d.instance.consumer_secret
|
32
|
-
assert_equal '
|
33
|
-
assert_equal '
|
32
|
+
assert_equal 'OAUTH_TOKEN', d.instance.oauth_token
|
33
|
+
assert_equal 'OAUTH_TOKEN_SECRET', d.instance.oauth_token_secret
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_emit
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-twitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
16
|
-
requirement: &
|
16
|
+
requirement: &11259400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11259400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fluentd
|
27
|
-
requirement: &
|
27
|
+
requirement: &11258160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,29 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11258160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: twitter
|
38
|
+
requirement: &11257360 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *11257360
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: tweetstream
|
49
|
+
requirement: &11283100 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *11283100
|
36
58
|
description:
|
37
59
|
email:
|
38
60
|
- y.ken.studio@gmail.com
|
@@ -46,8 +68,10 @@ files:
|
|
46
68
|
- README.md
|
47
69
|
- Rakefile
|
48
70
|
- fluent-plugin-twitter.gemspec
|
71
|
+
- lib/fluent/plugin/in_twitter.rb
|
49
72
|
- lib/fluent/plugin/out_twitter.rb
|
50
73
|
- test/helper.rb
|
74
|
+
- test/plugin/test_in_twitter.rb
|
51
75
|
- test/plugin/test_out_twitter.rb
|
52
76
|
homepage: https://github.com/y-ken/fluent-plugin-twitter
|
53
77
|
licenses: []
|
@@ -72,8 +96,9 @@ rubyforge_project:
|
|
72
96
|
rubygems_version: 1.8.11
|
73
97
|
signing_key:
|
74
98
|
specification_version: 3
|
75
|
-
summary: Fluentd Output
|
76
|
-
|
99
|
+
summary: Fluentd Input/Output plugin. You can create your own "Twitter Bot" with fluentd
|
100
|
+
messaging system.
|
77
101
|
test_files:
|
78
102
|
- test/helper.rb
|
103
|
+
- test/plugin/test_in_twitter.rb
|
79
104
|
- test/plugin/test_out_twitter.rb
|