7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/reddit_image_downloader/processor.rb', line 7
def process!
listings.each do |listing|
download = agent.get(listing["url"])
if download.is_a?(Mechanize::Image)
reader = Dimensions::Reader.new
reader << download.body
if reader.width >= options[:min_width] && reader.height >= options[:min_height]
filename = "#{listing["id"]}.#{reader.type}"
destination = File.join(options[:destination], filename)
unless File.exists?(destination)
download.save(destination)
end
end
end
end
if options[:max_age]
file_query = File.join(options[:destination], "*")
Dir[file_query].each do |file|
age = Time.now - File.ctime(file)
days_old = age / (24 * 3600)
if days_old > options[:max_age]
File.delete(file)
end
end
end
end
|