Created
March 9, 2015 16:50
-
-
Save johnmeehan/095edec6eac52861a437 to your computer and use it in GitHub Desktop.
Save 100 simularly named images stored remotely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
require 'net/http' | |
require 'uri' | |
### | |
# Purpose: | |
# Needed to save 100 simularly named images stored remotely | |
# Result: Saves 100 png to the local ./icons/ folder | |
### | |
#Set up the directory to save to | |
LOCATION = './icons/' | |
if !File.exist? LOCATION # create folder if it is not exist | |
require 'fileutils' | |
FileUtils.mkpath LOCATION | |
end | |
# cycle through each 100 images and perform the download. | |
(1..100).each do |number| | |
# image_url="http://www.example.com/newicons/red" + (number.to_s) + ".png" | |
image_url="http://www.example.com/newicons/black" + (number.to_s) + ".png" | |
uri = URI.parse(image_url) | |
name = File.basename(uri.path) | |
puts "FILENAME: #{name}" | |
File.open("#{LOCATION}#{name}", 'wb') do |file| | |
puts "FILE OPENED" | |
file.write(open(image_url).read) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment