Module: ImageFetcher

Defined in:
lib/image_fetcher.rb,
lib/image_fetcher/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.get_all_images(file, write_path = "", ext = "png") ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/image_fetcher.rb', line 7

def self.get_all_images(file, write_path = "", ext = "png")
	File.open(file, 'r').each_line do |line|
		begin
			encoded_url = URI.parse(URI.encode(line.chomp))
			file_name = DateTime.now.strftime('%Q')
 			Timeout::timeout(10) do
         open(encoded_url) do |uri|
 		      open("#{write_path}#{file_name}.#{ext}", "wb") do |file|
    			    file.write(uri.read)
    			  end
 		    end
       end
 		rescue Timeout::Error, Net::OpenTimeout, SocketError => e
 			e.message
		end
 	end
end