Skip to content

Instantly share code, notes, and snippets.

@itkq
Created February 6, 2018 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itkq/fbd1cf0df27f511566371fc8e56a6933 to your computer and use it in GitHub Desktop.
Save itkq/fbd1cf0df27f511566371fc8e56a6933 to your computer and use it in GitHub Desktop.
require 'fileutils'
require 'pathname'
require 'open-uri'
require 'net/http'
URL_TEMPLATE = 'http://t7s.jp/image/page/release/ingame/cover/%02d.png'
def save(url, base_path)
puts url
data = open(url).read
filename = File.basename(url)
open(Pathname.new(base_path) + filename, 'wb') do |out|
out.write(data)
end
end
def main
save_dir = Pathname.new(File.expand_path('..', __FILE__)).join("cover")
FileUtils.mkdir_p(save_dir)
[*1..99].each do |i|
begin
save(URL_TEMPLATE % [i], save_dir)
rescue OpenURI::HTTPError
puts "#{$!.class}: #{$!.message}"
exit
end
sleep 1
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment