@
GPU require 'net/http'
require "cairo"
def get_url time, x, y
str = "
http://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/#{time}00_#{x}_#{y}.png"
end
def merge time
puts "Start image process"
w = 20
h = 20
partial_width = 550
surface = Cairo::ImageSurface.new(w * partial_width, h * partial_width)
cr = Cairo::Context.new(surface)
arr = []
h.times do |y|
w.times do |x|
name = "himawari_#{x}_#{y}.png"
arr.push name
puts name
png = Cairo::ImageSurface.from_png(name)
cr.set_source(*png)
cr.matrix = Cairo::Matrix.new(1,0,0,1,x * partial_width, y * partial_width)
cr.paint()
end
end
cr.target.write_to_png("#{time.split("/").join("_")}.png")
cr.destroy
surface.destroy
arr.each do |file|
File.delete file
end
end
def run time
merge_name = time.split("/").join("_") + ".png"
unless File.exists? merge_name
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)
file.close
end
end
end
ts.push thread
end
ts.map(&:join)
sleep 5
end
unless File.exists? merge_name
merge time
end
end
24.times do |hour|
hour = hour.to_s
if hour.length < 2
hour = "0" + hour
end
6.times do |minute|
minute = (minute * 10).to_s
if minute.length < 2
minute = "0" + minute
end
str = "2015/12/01/" + hour + minute
puts str
run str
end
end
# run "2015/12/01/0000"