Skip to content

Instantly share code, notes, and snippets.

@mizukmb
Last active August 29, 2015 14:06
Show Gist options
  • Save mizukmb/963ff8408b454805c1ad to your computer and use it in GitHub Desktop.
Save mizukmb/963ff8408b454805c1ad to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require "twitter"
require 'open-uri'
require 'nokogiri'
CONSUMER_KEY = "あなたのCONSUMER_KEY"
CONSUMER_SECRET = "あなたのCONSUMER_SECRET"
OAUTH_TOKEN = "あなたのOAUTH_TOKEN"
OAUTH_TOKEN_SECRET = "あなたのOAUTH_TOKEN_SECRET"
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
p icon = icon_urls[rand(686)+1]
puts "アイコンをセットしますか?[ y/n ]:"
yn = gets.chomp
if yn == 'y'
killme_twitter.update_profile_image(OpenURI.open_uri(icon))
killme_twitter.update('キルミーアイコンを' + icon+ "に設定しました #killme_icon")
else
exit(0)
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