Skip to content

Instantly share code, notes, and snippets.

@keisei1092
Created April 16, 2017 06:56
Show Gist options
  • Save keisei1092/831f202f659c1e9e89573178ce611d67 to your computer and use it in GitHub Desktop.
Save keisei1092/831f202f659c1e9e89573178ce611d67 to your computer and use it in GitHub Desktop.
新着ツイートを監視してニコニコのURLを含んでいたらなにかするやつ
# 新着ツイートを監視してニコニコのURLを含んでいたらなにかするやつ
#
# Usage
# gem install tweetstream
# CONSUMER_KEY= CONSUMER_SECRET= OAUTH_TOKEN= OAUTH_SECRET= ruby vocalonobis_watcher.rb
require 'tweetstream'
class String
def includesNicoUrl?
return self.include? 'nicovideo.jp'
end
end
TweetStream.configure do |config|
config.consumer_key = ENV['CONSUMER_KEY']
config.consumer_secret = ENV['CONSUMER_SECRET']
config.oauth_token = ENV['OAUTH_TOKEN']
config.oauth_token_secret = ENV['OAUTH_SECRET']
config.auth_method = :oauth
end
VOCALONOBIS = 291513619
TweetStream::Client.new.follow(VOCALONOBIS) do |status|
url = status
.uris
.map(&:expanded_url)
.map(&:to_s)
.select(&:includesNicoUrl?)
.first
.to_s
return if url.empty?
# ここでなにかする
puts url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment