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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 53436719b93625ed57416f119407b05589b336b6
4
- data.tar.gz: b74944ebfc0f12593c21b746d67a8367ea53030e
2
+ SHA256:
3
+ metadata.gz: 163a699d485f9c986265105fceb48ca8af2fa95746e5bf09a01d1877b319d004
4
+ data.tar.gz: 967c8cedd7af22e47b02c8b743a130decf08e8c4cab0fe6f954e9f6fa216e240
5
5
  SHA512:
6
- metadata.gz: 14d5b439c7b8478a3bfea963d9b7d27935d043ff17322e48d0eb72d5a73d2ce639ac30e8b9635981ba98da542a6e719592dc39bc2ad4404586673cee98ae81f7
7
- data.tar.gz: e8a9fae9abe23cb1d2558b972c119796f8806a4dc48df3c136d05bd8452216f50d1eaa9a169ec17c06ad2ec7e605845e7ac2b33cf2c87d3e9ec7fdcc665d1ded
6
+ metadata.gz: aa2c25f3ff9c777a5952b681066039891082972fda176450e662c65e5267bc91ca670db8a04cd87b6a35f130f4b9ebb6d51ea0af6e8f650bd735f8d4a7614110
7
+ data.tar.gz: f04bd596287ecb0a5ed5690c6bc004b8cfec27fca76e27ac651a1a9fb3221764c69149aa0d6eae70fb01e3604b53775864f6400f84958e11632eae942cab284b
data/Dockerfile CHANGED
@@ -1,10 +1,10 @@
1
- FROM ruby:latest
1
+ FROM ruby:alpine
2
2
 
3
- MAINTAINER ABCanG <abcang1015@gmail.com>
3
+ MAINTAINER abcang <abcang1015@gmail.com>
4
4
 
5
- # timezone
6
- RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
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
- RUN gem install slack_twitter_egosa
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
- * `USER_STREAM_WORDS`: 自分のタイムラインから検索するワード。スペース区切りで複数指定可能。
24
- * `FILTER_STREAM_WORDS`: Twitter全体から検索するワード。スペース区切りで複数指定可能。
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
- USER_STREAM_WORDS=阿部 あべ
38
- FILTER_STREAM_WORDS=abcang ABCanG1015 -@ABCanG1015
39
- MUTE_USERS=ABCanG1015
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 "USER_STREAM_WORDS=阿部 あべ" \
54
- -e "FILTER_STREAM_WORDS=abcang ABCanG1015 -@ABCanG1015" \
55
- -e "MUTE_USERS=ABCanG1015" \
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
File without changes
@@ -1,3 +1,3 @@
1
1
  module SlackTwitterEgosa
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -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 'tweetstream'
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
- user_stream_thread,
27
- filter_stream_thread
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 init_twitter
46
- TweetStream.configure do |config|
47
- config.consumer_key = ENV['CONSUMER_KEY']
48
- config.consumer_secret = ENV['CONSUMER_SECRET']
49
- config.oauth_token = ENV['OAUTH_TOKEN']
50
- config.oauth_token_secret = ENV['OAUTH_TOKEN_SECRET']
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 user_stream
60
- @user_stream ||= WordManager.new(ENV['USER_STREAM_WORDS'])
56
+ def home_timeline_words
57
+ @home_timeline_words ||= WordManager.new(ENV['HOME_TIMELINE_WORDS'])
61
58
  end
62
59
 
63
- def filter_stream
64
- @filter_stream ||= WordManager.new(ENV['FILTER_STREAM_WORDS'])
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 user_stream_thread
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
- TweetStream::Client.new.userstream do |status|
74
- if status.retweet?
75
- status = status.retweeted_status
76
- next if status.user.following?
77
- end
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
- if mute_users.unmatch?(status.user.screen_name) &&
80
- user_stream.match?(CGI.unescapeHTML(status.full_text))
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 filter_stream_thread
103
+ def search_thread
88
104
  Thread.new do
89
- TweetStream::Client.new.track(*filter_stream.target) do |status|
90
- if !status.retweet? && mute_users.unmatch?(status.user.screen_name) &&
91
- filter_stream.unmatch_exclude?(CGI.unescapeHTML(status.full_text))
92
- poster.post_status(status)
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
@@ -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 = ['ABCanG']
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.1.1'
22
+ spec.add_dependency 'dotenv', '~> 2.4.0'
23
23
  spec.add_dependency 'slack-poster', '~> 2.2.0'
24
- spec.add_dependency 'tweetstream', '~> 2.6.1'
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.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - ABCanG
7
+ - abcang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
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.1.1
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.1.1
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: tweetstream
42
+ name: twitter
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.6.1
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.6.1
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.5.1
142
+ rubygems_version: 2.7.6
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Eegosearching twitter and post to slack.