P
patrick.anthony124
Hey everyone. This is the first time I've written something in Ruby to do something for myself, everything else has been some how part of an assignment or a tutorial or a walk-through. I want this script to download a series of .png files and save them locally in the same order. I have posted it below but it just doesn't seem to work. Any help or suggestions would be greatly appreciated.
require "net/http"
remote_base_url = "https://path.to/the/folder"
start_page = 001
end_page = 281
# Images are named p001.png to p281.png.
(start_page..end_page).each do |it|
rpage = open(remote_base_url + "/" + "p" + it.to_s)
local_fname = "copy-of-" + it.to_s + ".png"
local_file = open(local_fname, "w")
local_file.write(rpage.read)
local_file.close
# Optional output line:
puts "Wrote file " + local_fname
sleep 1
end
# Write to the compiled file now:
compiled_file = open(start_page.to_s + "-" + end_page.to_s + ".png", "w")
(start_page..end_page).each do |it|
local_fname = "copy-of-" + it.to_s + ".png"
local_file = open(local_fname, "r")
compiled_file.write(local_file.read)
local_file.close
end
compiled_file.close
require "net/http"
remote_base_url = "https://path.to/the/folder"
start_page = 001
end_page = 281
# Images are named p001.png to p281.png.
(start_page..end_page).each do |it|
rpage = open(remote_base_url + "/" + "p" + it.to_s)
local_fname = "copy-of-" + it.to_s + ".png"
local_file = open(local_fname, "w")
local_file.write(rpage.read)
local_file.close
# Optional output line:
puts "Wrote file " + local_fname
sleep 1
end
# Write to the compiled file now:
compiled_file = open(start_page.to_s + "-" + end_page.to_s + ".png", "w")
(start_page..end_page).each do |it|
local_fname = "copy-of-" + it.to_s + ".png"
local_file = open(local_fname, "r")
compiled_file.write(local_file.read)
local_file.close
end
compiled_file.close