require 'net/http'
def get_url time, x, y
str = "
http://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/#{time}0000_#{x}_#{y}.png"
end
def run time
ts = []
20.times do |x|
thread = Thread.new do
20.times do |y|
name = "himawari_#{x}_#{y}.png"
unless File.exists? name
url = get_url time, x, y
uri = URI.parse(url)
req = Net::HTTP::Get.new uri.path
res = Net::HTTP.start(uri.host, uri.port, use_ssl: false) do |http|
http.request req
end
file = File.open(name, "w+")
file.write(res.body)
end
end
end
ts.push thread
end
ts.map(&:join)
end
run "2015/12/08/01"
require "cairo"
w = 20
h = 20
time = "05"
partial_width = 550
surface = Cairo::ImageSurface.new(w * partial_width, h * partial_width)
cr = Cairo::Context.new(surface)
w.times do |x|
h.times do |y|
name = "#{time}/himawari_#{x}_#{y}.png"
puts name
png = Cairo::ImageSurface.from_png(name)
cr.set_source(*png)
cr.matrix = Cairo::Matrix.identity
cr.translate(x * partial_width, y * partial_width)
cr.paint()
end
end
cr.target.write_to_png("all.png")