Skip to content

Instantly share code, notes, and snippets.

@mizukmb
Last active Aug 29, 2015
Embed
What would you like to do?
# -*- 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