Skip to content

Instantly share code, notes, and snippets.

@mudhappy
Created April 14, 2020 19:26
Show Gist options
  • Save mudhappy/c5250aa7144df0f2cd6586982def8e39 to your computer and use it in GitHub Desktop.
Save mudhappy/c5250aa7144df0f2cd6586982def8e39 to your computer and use it in GitHub Desktop.
download images
get 'get_download' => "application#download"
def download
require "open-uri"
require 'fileutils'
tours = [
["421","https://www.graylinecostarica.com/uploads/tours/TOUC05-5.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-6.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-7.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-8.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-9.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-10.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-25.JPG,https://www.graylinecostarica.com/uploads/tours/TOUC05-26.JPG"],
]
tours.each do |tour|
FileUtils.mkdir_p "images_cr/#{tour[0]}"
tour[1].split(',').each_with_index do |photo, index|
begin
open(photo) {|f|
File.open("images_cr/#{tour[0]}/#{index}_original.jpg","wb") do |file|
file.puts f.read
photo = Magick::Image.read("images_cr/#{tour[0]}/#{index}_original.jpg").first
puts "images_cr/#{tour[0]}/#{index}_big.jpg"
end
}
rescue => exception
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment