Created
August 8, 2013 17:20
-
-
Save k0kubun/6186675 to your computer and use it in GitHub Desktop.
Twitterのアイコンをランダムでキルミーベイベー(http://killmebaby.tv/special_icon.html)にするやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- Usage --- | |
# ruby kmb.rb init | |
# ruby kmb.rb change | |
require 'twitter' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'fileutils' | |
Twitter.configure do |config| | |
config.consumer_key = '' | |
config.consumer_secret = '' | |
config.oauth_token = '' | |
config.oauth_token_secret = '' | |
end | |
img_dir = File.expand_path('~/kmb') | |
FileUtils.mkdir_p(img_dir) | |
case ARGV[0] | |
when "init" | |
doc = Nokogiri::HTML(open("http://killmebaby.tv/special_icon.html")) | |
doc.xpath('//*[@id="icon_waku"]/div/table/tr/td/img').each do |img_tag| | |
img_url = 'http://killmebaby.tv/' + img_tag.attributes["src"].value | |
File::open("#{img_dir}/#{img_url.gsub(/^.+\//, '')}", "wb") do |file| | |
open(img_url) do |img| | |
file.write(img.read) | |
end | |
end | |
end | |
when "change" | |
img_files = Dir.glob("#{img_dir}/*") | |
img_file = img_files[rand(img_files.length)] | |
Twitter.update_profile_image(File.new(img_file)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment