Skip to content

Instantly share code, notes, and snippets.

@sudosanet
Forked from mizukmb/killme.rb
Last active August 29, 2015 14:15
Show Gist options
  • Save sudosanet/d34921843ae099a3a913 to your computer and use it in GitHub Desktop.
Save sudosanet/d34921843ae099a3a913 to your computer and use it in GitHub Desktop.
update_killme
# -*- coding: utf-8 -*-
require "twitter"
require 'open-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など)"
url = 'http://killmebaby.tv/special_icon.html'
html = open(url).read
doc = Nokogiri::HTML(html, url)
icon_urls = Array.new
doc.css('img').each do |link|
if /http:\/\/aka\.saintpillia\.com\/killme\/icon\/[0-9_-]{3,}\.png/ =~ link[:src]
icon_urls.push(link[:src])
end
end
begin
killme_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 ="killme_updateを起動しました、僕にkillmeとリプを送るとアイコンがランダムで変わります \n" + Time.now.to_s
killme_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} killme") && !status.text.include?("RT") then
p icon = icon_urls[rand(686)+1]
killme_twitter.update_profile_image(OpenURI.open_uri(icon))
t = Time.now
strTime = t.strftime("%H時 %M分 %S秒")
option = {"in_reply_to_status_id"=>status.id.to_s}
tweet = ". @#{status.user.screen_name} キルミーアイコンを" + icon + "に設定しました #killme_icon \n #{strTime}"
p tweet
killme_twitter.update tweet,option
end
end
rescue => e
STDERR.puts "[EXCEPTION] " + e.to_s
exit 1
end
@sudosanet
Copy link
Author

update_nameっぽいものにしてみた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment