module ImageFetcher

Constants

VERSION

Public Class Methods

get_all_images(file, write_path = "", ext = "png") click to toggle source
# 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, Errno::ECONNREFUSED => e
                       e.message
                       end
       end
       end