Skip to content

Instantly share code, notes, and snippets.

@sota1235
Created February 8, 2014 16:01
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 sota1235/8885899 to your computer and use it in GitHub Desktop.
Save sota1235/8885899 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
# Date 2014/02/08
# Created by sota1235
require 'open-uri'
# 成功したら配列から削除
$array = [*1..1368]
def save_pic(url)
fName = File.basename(url)
# ファイル保存場所
path = "/hoge/" + fName
begin
open(path,'wb') do |output|
open(url) do |data|
output.write(data.read)
end
end
print(fName," is success.\n")
$array.delete(fName.delete(".png").to_i)
$array.insert fName.delete(".png").to_i - 1, "x" # xを突っ込むことでfor文でのポインタずれを回避
rescue
print(fName," is failed.\n")
File.unlink path
end
end
base1 = "http://hoge-"
base2 = "-moge/"
for num1 in 48..57 do
for num2 in $array do
unless num2=='x'
save_pic(base1 + num1.to_s + base2 + num2.to_s + ".png")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment