Created
May 25, 2013 06:34
-
-
Save cesare/5648158 to your computer and use it in GitHub Desktop.
Usage: rubyist-pics.rb LOCAL/PATH/TO/darashi/rubyistokei/data
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
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'net/https' | |
require 'yaml' | |
datadir = ARGV.shift | |
filenames = Dir.entries(datadir).select {|name| name =~ /\.(yml|yaml)$/} | |
rubyists = filenames.map {|filename| YAML.load_file(File.join(datadir, filename)).merge('filename' => filename) } | |
destdir = 'rubyists' | |
FileUtils.mkdir_p destdir, mode: 0755 | |
rubyists.each do |rubyist| | |
filename = rubyist['filename'] | |
name = filename.gsub /\.(yml|yaml)$/, '' | |
print "Loading image of #{name}..." | |
uri = URI(rubyist['url']) | |
options = uri.scheme == 'https' ? {use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE} : {} | |
response = Net::HTTP.start(uri.host, options) do |http| | |
http.get uri.request_uri | |
end | |
File.open(File.join(destdir, "#{name}.jpg"), File::CREAT|File::TRUNC|File::RDWR, 0644) do |out| | |
out.write response.body | |
end | |
puts 'ok' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment