Skip to content

Instantly share code, notes, and snippets.

@nkpoid
Forked from sudosanet/update_eupho.rb
Last active August 29, 2015 14:21
Show Gist options
  • Save nkpoid/87c522cac3b0bc7409e3 to your computer and use it in GitHub Desktop.
Save nkpoid/87c522cac3b0bc7409e3 to your computer and use it in GitHub Desktop.
require "open-uri"
require "uri"
require "nokogiri"
require 'tweetstream'
CONSUMER_KEY = "あなたのCONSUMER_KEY"
CONSUMER_SECRET = "あなたのCONSUMER_SECRET"
OAUTH_TOKEN = "あなたのOAUTH_TOKEN"
OAUTH_TOKEN_SECRET = "あなたのOAUTH_TOKEN_SECRET"
YOUR_ID = "あなたのTwitterID (@sudosanなど)"
icon_urls=[]
url = "http://anime-eupho.com/special/"
doc = Nokogiri::HTML.parse(open(url))
doc.css('img').each do |node|
path = node.attributes["src"].value
next if path !~ /special\/twitter\/thumb/
path.gsub!("thumb","icon").gsub!("jpg","png")
icon_urls << "http://anime-eupho.com"+path
end
begin
eupho_twitter = Twitter::REST::Client.new do |cnf|
cnf.consumer_key = CONSUMER_KEY
cnf.consumer_secret = CONSUMER_SECRET
cnf.access_token = OAUTH_TOKEN
cnf.access_token_secret = OAUTH_TOKEN_SECRET
end
tw ="eupho_updateを起動しました、僕にeuphoとリプを送るとアイコンがランダムで変わります \n" + Time.now.to_s
eupho_twitter.update tw
TweetStream.configure do |cnf|
cnf.consumer_key = CONSUMER_KEY
cnf.consumer_secret = CONSUMER_SECRET
cnf.oauth_token = OAUTH_TOKEN
cnf.oauth_token_secret = OAUTH_TOKEN_SECRET
cnf.auth_method = :oauth
end
client = TweetStream::Client.new
client.userstream do |status|
if status.text.downcase.include?("#{YOUR_ID} eupho") && !status.text.include?("RT")
icon_url = icon_urls.sample
eupho_twitter.update_profile_image(open(icon_url))
t = Time.now
strTime = t.strftime("%H時 %M分 %S秒")
tweet = ". @#{status.user.screen_name} ユーフォニアムアイコンを#{icon_url}に設定しました #eupho_icon \n #{strTime}"
option = {"in_reply_to_status_id"=>status.id.to_s}
p tweet
eupho_twitter.update tweet,option
end
end
rescue => e
STDERR.puts "[EXCEPTION] " + e.to_s
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment