Last active
February 5, 2019 01:16
-
-
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
This file contains hidden or 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 '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