3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Twitterのタイムラインを監視してSlackに通知するやつ作った

Posted at

TLを見ていない時やTLが早過ぎて見たいツイートを見逃してしまうことがよくあるので、Streaming APIを使ってTLを監視しつつ条件にしたがってSlackに通知するやつを作ってみました

Earch

Github: flum1025/earch
Rubygems: earch
Docker: flum1025/earch

使い方

gemを直接インストールして使う方法とDockerを使う2種類の使い方があります

gemをインストール

$ gem install earch         #インストール
$ vim setting.yml             #設定ファイルを用意
$ earch -s setting.yml   #実行

Dockerを使う

$ git clone https://github.com/flum1025/earch.git  #gitからクローン
$ vim setting.yml                                        #設定ファイルを用意
$ docker-compose up                                 #実行

設定ファイル

実行する前にyaml形式で設定ファイルを用意する必要があります
requireなものはflum1025/earch#exampleを見てください

example.yml
twitter:
  stream_options:
    replies: all                               #streamに他人のリプライを含むか
  screen_name: flum_                           #Twitterのスクリーンネーム
  api_key:                                     #Twitterのトークン
    consumer_key: CONSUMER_KEY
    consumer_secret: CONSUMER_SECRET
    access_token: ACCESS_TOKEN
    access_token_secret: ACCESS_TOKEN_SECRET
slack:
  api_key:                                     #Slackのトークン
    token: xxxxxxxxxxxxxxxxxxx
  user_icon: ':earch:'                         #Slackのbotに使うアイコン
  notify_channel: '#earch'                     #通知のチャンネル
  icon: ':flum_:'                              #Twitterのアイコン(複数アカウントで監視する場合にわかりやすくなる)
rules:                                         #条件を指定
  - text: !ruby/regexp /test.*/
    screen_name: twitterdev

Rule

複数の条件を指定することができます
使えるデータタイプはflum1025/earch#rulesを参照してください

example
rules:
  - text: !ruby/regexp /test/          #正規表現/test/にマッチし、スクリーンネームがtwitterdevのツイートを抽出
    screen_name: twitterdev
  - hashtag:                           #'test'か'events'のハッシュタグが含まれていて、且つお気に入り数が50以上のもの
      - test
      - events
    favorite_count: 50
  - retweet_count: !ruby/range 0..10   # リツイート数が0~10のもの
  - lang: ja                           #Tweetの言語がjaでリツイート、クゥオートでなく、誰かへのリプライのツイート
    retweet: false
    quote: false
    reply: true

今後

含まない等の否定の条件を入れれるようにする
もしバグを見つけたら@flum_またはissuesまでお願いします!

3
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?