Skip to content

Instantly share code, notes, and snippets.

@Santarh
Created February 28, 2012 16:51
Show Gist options
  • Save Santarh/1933607 to your computer and use it in GitHub Desktop.
Save Santarh/1933607 to your computer and use it in GitHub Desktop.
何かのダウンロード
require "net/http"
$host_ip = "255.255.255.0"
$directory = "/h/f/p/g/"
$extension = ".jpg"
# サーバへの気持ち
$wait_time = 0.5
$type = (1..3).to_a
$rank = (0..5).to_a
$num = (1..100).to_a
def is_rank_plus? rank
return rank%2 == 1
end
# RETURN: File Exists?
def save_file file
data = Net::HTTP.get $host_ip, ( $directory + file )
p "http request :#{file}"
return false if data =~ /Not Found/
f = open file, "w"
f.write data
f.close
p "save :#{file}"
return true
end
def get_character_cards type, rank, number, diffs
diffs.each do |d|
file = ( sprintf "%d%d%03d%02d%s", type, rank, number, d, $extension )
next if FileTest.exists? file
break unless save_file file
end
end
# 欠番
f = open "3302002.jpg", "w"
f.close
# main
$type.each do |t|
$rank.each do |r|
$num.each do |n|
next if Dir::glob( sprintf "%d%d%03d*%s", t, r, n, $extension ).any?
sleep $wait_time
if is_rank_plus? r
get_character_cards t, r, n, [2]
get_character_cards t, r, n, [5, 6, 7, 8, 9]
get_character_cards t, r, n, [11]
else
get_character_cards t, r, n, [1, 2, 3, 4]
get_character_cards t, r, n, [10]
end
break unless Dir::glob( sprintf "%d%d%03d*%s", t, r, n, $extension ).any?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment