Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
新着ツイートを監視してニコニコの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