Skip to content

Instantly share code, notes, and snippets.

@rush2sk8
Last active February 5, 2019 01:16
Show Gist options
  • Save rush2sk8/8ea69a12f696716769f6703cd96cc18a to your computer and use it in GitHub Desktop.
Save rush2sk8/8ea69a12f696716769f6703cd96cc18a to your computer and use it in GitHub Desktop.
given a file with image urls itll download them to a directory of that filename
require 'open-uri'
def download_image(url, dest)
open(url) do |u|
File.open(dest, "wb") { |f| f.write(u.read)}
end
end
files = []
s = Time.now
files.each{ |file|
x = 0
dir = file.split(".")[0]
puts "Creating #{dir}/"
Dir.mkdir "#{file.split(".")[0]}"
totalLines = File.open(file, "r").readlines.size
IO.foreach(file) do |url|
begin
download_image(url.chomp, "#{dir}/#{url.split('/').last.chomp}")
rescue
next
end
x = x + 1
puts "#{x}/#{totalLines}"
end
}
puts "Time taken #{Time.now-s}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment