slack_twitter_egosa 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Dockerfile +7 -7
- data/README.md +9 -8
- data/exe/slack_twitter_egosa +0 -0
- data/lib/slack_twitter_egosa/version.rb +1 -1
- data/lib/slack_twitter_egosa.rb +57 -30
- data/slack_twitter_egosa.gemspec +3 -3
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 163a699d485f9c986265105fceb48ca8af2fa95746e5bf09a01d1877b319d004
|
4
|
+
data.tar.gz: 967c8cedd7af22e47b02c8b743a130decf08e8c4cab0fe6f954e9f6fa216e240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa2c25f3ff9c777a5952b681066039891082972fda176450e662c65e5267bc91ca670db8a04cd87b6a35f130f4b9ebb6d51ea0af6e8f650bd735f8d4a7614110
|
7
|
+
data.tar.gz: f04bd596287ecb0a5ed5690c6bc004b8cfec27fca76e27ac651a1a9fb3221764c69149aa0d6eae70fb01e3604b53775864f6400f84958e11632eae942cab284b
|
data/Dockerfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
FROM ruby:
|
1
|
+
FROM ruby:alpine
|
2
2
|
|
3
|
-
MAINTAINER
|
3
|
+
MAINTAINER abcang <abcang1015@gmail.com>
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
RUN apk add --update make g++ && \
|
6
|
+
gem install slack_twitter_egosa && \
|
7
|
+
apk del make && \
|
8
|
+
rm -rf /var/cache/apk/*
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
CMD slack_twitter_egosa
|
10
|
+
CMD ["slack_twitter_egosa"]
|
data/README.md
CHANGED
@@ -20,8 +20,8 @@ TwitterでエゴサしてSlackに投稿します。
|
|
20
20
|
* `CONSUMER_SECRET`: TwitterのConsumer Secret
|
21
21
|
* `OAUTH_TOKEN`: TwitterのAccess Token
|
22
22
|
* `OAUTH_TOKEN_SECRET`: TwitterのAccess Token Secret
|
23
|
-
* `
|
24
|
-
* `
|
23
|
+
* `HOME_TIMELINE_WORDS`: 自分のタイムラインから検索するワード。スペース区切りで複数指定可能。
|
24
|
+
* `SEARCH_WORDS`: Twitter全体から検索するワード。スペース区切りで複数指定可能。
|
25
25
|
* `MUTE_USERS`: エゴサ対象外にするユーザ。スペース区切りで複数指定可能。
|
26
26
|
|
27
27
|
## 普通に起動
|
@@ -34,9 +34,9 @@ CONSUMER_KEY=XXXXXXXX
|
|
34
34
|
CONSUMER_SECRET=XXXXXXXX
|
35
35
|
OAUTH_TOKEN=XXXXXXXX
|
36
36
|
OAUTH_TOKEN_SECRET=XXXXXXXX
|
37
|
-
|
38
|
-
|
39
|
-
MUTE_USERS=
|
37
|
+
HOME_TIMELINE_WORDS=阿部 あべ
|
38
|
+
SEARCH_WORDS=abcang abcang1015 -@abcang1015
|
39
|
+
MUTE_USERS=abcang1015
|
40
40
|
^D
|
41
41
|
$ slack_twitter_egosa .env
|
42
42
|
```
|
@@ -50,9 +50,9 @@ docker run \
|
|
50
50
|
-e "CONSUMER_SECRET=XXXXXXXX" \
|
51
51
|
-e "OAUTH_TOKEN=XXXXXXXX" \
|
52
52
|
-e "OAUTH_TOKEN_SECRET=XXXXXXXX" \
|
53
|
-
-e "
|
54
|
-
-e "
|
55
|
-
-e "MUTE_USERS=
|
53
|
+
-e "HOME_TIMELINE_WORDS=阿部 あべ" \
|
54
|
+
-e "SEARCH_WORDS=abcang abcang1015 -@abcang1015" \
|
55
|
+
-e "MUTE_USERS=abcang1015" \
|
56
56
|
abcang/slack-twitter-egosa
|
57
57
|
```
|
58
58
|
|
@@ -60,6 +60,7 @@ docker run \
|
|
60
60
|
* 2016/08/23: 公開
|
61
61
|
* 2016/09/20: ミュートユーザ、除外キーワード機能を追加
|
62
62
|
* 2016/09/22: 除外キーワードバグの修正、gemで公開、大文字小文字を区別しないようにした
|
63
|
+
* 2018/05/21: ストリーミングAPIを使わないように変更(90秒に1回REST APIを叩く)
|
63
64
|
|
64
65
|
## ライセンス
|
65
66
|
MIT
|
data/exe/slack_twitter_egosa
CHANGED
File without changes
|
data/lib/slack_twitter_egosa.rb
CHANGED
@@ -4,7 +4,7 @@ require 'slack_twitter_egosa/word_manager'
|
|
4
4
|
require 'slack_twitter_egosa/user_filter'
|
5
5
|
|
6
6
|
require 'dotenv'
|
7
|
-
require '
|
7
|
+
require 'twitter'
|
8
8
|
|
9
9
|
module SlackTwitterEgosa
|
10
10
|
class << self
|
@@ -20,11 +20,9 @@ module SlackTwitterEgosa
|
|
20
20
|
exit 1
|
21
21
|
end
|
22
22
|
|
23
|
-
init_twitter
|
24
|
-
|
25
23
|
threads = [
|
26
|
-
|
27
|
-
|
24
|
+
home_timeline_thread,
|
25
|
+
search_thread
|
28
26
|
]
|
29
27
|
threads.each(&:join)
|
30
28
|
end
|
@@ -42,13 +40,12 @@ module SlackTwitterEgosa
|
|
42
40
|
target_env - env_list
|
43
41
|
end
|
44
42
|
|
45
|
-
def
|
46
|
-
|
47
|
-
config.consumer_key
|
48
|
-
config.consumer_secret
|
49
|
-
config.
|
50
|
-
config.
|
51
|
-
config.auth_method = :oauth
|
43
|
+
def client
|
44
|
+
@client ||= Twitter::REST::Client.new do |config|
|
45
|
+
config.consumer_key = ENV['CONSUMER_KEY']
|
46
|
+
config.consumer_secret = ENV['CONSUMER_SECRET']
|
47
|
+
config.access_token = ENV['OAUTH_TOKEN']
|
48
|
+
config.access_token_secret = ENV['OAUTH_TOKEN_SECRET']
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
@@ -56,40 +53,70 @@ module SlackTwitterEgosa
|
|
56
53
|
@poster ||= SlackPoster.new(ENV['WEBHOOK_URL'])
|
57
54
|
end
|
58
55
|
|
59
|
-
def
|
60
|
-
@
|
56
|
+
def home_timeline_words
|
57
|
+
@home_timeline_words ||= WordManager.new(ENV['HOME_TIMELINE_WORDS'])
|
61
58
|
end
|
62
59
|
|
63
|
-
def
|
64
|
-
@
|
60
|
+
def search_words
|
61
|
+
@search_words ||= WordManager.new(ENV['SEARCH_WORDS'])
|
65
62
|
end
|
66
63
|
|
67
64
|
def mute_users
|
68
65
|
@mute_users ||= UserFilter.new(ENV['MUTE_USERS'])
|
69
66
|
end
|
70
67
|
|
71
|
-
def
|
68
|
+
def match_on_home_timeline?(status)
|
69
|
+
if status.retweet?
|
70
|
+
status = status.retweeted_status
|
71
|
+
return false if status.user.following?
|
72
|
+
end
|
73
|
+
|
74
|
+
mute_users.unmatch?(status.user.screen_name) && home_timeline_words.match?(CGI.unescapeHTML(status.full_text))
|
75
|
+
end
|
76
|
+
|
77
|
+
def match_on_search?(status)
|
78
|
+
!status.retweet? && mute_users.unmatch?(status.user.screen_name) &&
|
79
|
+
search_words.unmatch_exclude?(CGI.unescapeHTML(status.full_text))
|
80
|
+
end
|
81
|
+
|
82
|
+
def home_timeline_thread
|
72
83
|
Thread.new do
|
73
|
-
|
74
|
-
if
|
75
|
-
|
76
|
-
|
77
|
-
|
84
|
+
loop do
|
85
|
+
sleep 90 if @home_timeline_since_id
|
86
|
+
|
87
|
+
params = { count: 200 }
|
88
|
+
params[:since_id] = @home_timeline_since_id if @home_timeline_since_id
|
89
|
+
statuses = client.home_timeline(params)
|
90
|
+
next if statuses.empty?
|
91
|
+
|
92
|
+
before_home_timeline_since_id = @home_timeline_since_id
|
93
|
+
@home_timeline_since_id = statuses.first.id
|
94
|
+
next unless before_home_timeline_since_id
|
78
95
|
|
79
|
-
|
80
|
-
|
81
|
-
poster.post_status(status)
|
96
|
+
statuses.each do |status|
|
97
|
+
poster.post_status(status) if match_on_home_timeline?(status)
|
82
98
|
end
|
83
99
|
end
|
84
100
|
end
|
85
101
|
end
|
86
102
|
|
87
|
-
def
|
103
|
+
def search_thread
|
88
104
|
Thread.new do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
105
|
+
loop do
|
106
|
+
sleep 90 if @search_since_id
|
107
|
+
|
108
|
+
params = { result_type: 'recent', count: 100 }
|
109
|
+
params[:since_id] = @search_since_id if @search_since_id
|
110
|
+
q = search_words.target.join(' OR ') + ' ' + search_words.exclude.map { |word| "-#{word}" }.join(' ')
|
111
|
+
statuses = client.search(q, params).to_a
|
112
|
+
next if statuses.empty?
|
113
|
+
|
114
|
+
before_search_since_id = @search_since_id
|
115
|
+
@search_since_id = statuses.first.id
|
116
|
+
next unless before_search_since_id
|
117
|
+
|
118
|
+
statuses.each do |status|
|
119
|
+
poster.post_status(status) if match_on_search?(status)
|
93
120
|
end
|
94
121
|
end
|
95
122
|
end
|
data/slack_twitter_egosa.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'slack_twitter_egosa/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'slack_twitter_egosa'
|
8
8
|
spec.version = SlackTwitterEgosa::VERSION
|
9
|
-
spec.authors = ['
|
9
|
+
spec.authors = ['abcang']
|
10
10
|
spec.email = ['abcang1015@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'Eegosearching twitter and post to slack.'
|
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency 'dotenv', '~> 2.
|
22
|
+
spec.add_dependency 'dotenv', '~> 2.4.0'
|
23
23
|
spec.add_dependency 'slack-poster', '~> 2.2.0'
|
24
|
-
spec.add_dependency '
|
24
|
+
spec.add_dependency 'twitter', '~> 6.2.0'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_twitter_egosa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- abcang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: slack-poster
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: twitter
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 6.2.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 6.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.7.6
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Eegosearching twitter and post to slack.
|