Class: Flickr::Downloader
- Inherits:
-
Object
- Object
- Flickr::Downloader
- Defined in:
- lib/flickr/downloader.rb
Constant Summary collapse
- MAX_RETRIES =
10- PER_PAGE =
500
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(flickr) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(flickr) ⇒ Downloader
Returns a new instance of Downloader.
4 5 6 |
# File 'lib/flickr/downloader.rb', line 4 def initialize(flickr) @flickr = flickr end |
Instance Method Details
#download ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/flickr/downloader.rb', line 12 def download page = ENV['FLICKR_STARTING_PAGE'].to_i loop do page += 1 begin retry_count ||= 0 images = @flickr.people.getPhotos(user_id: ENV['FLICKR_USER_ID'], page: page, per_page: PER_PAGE) pb = ProgressBar.create(title: "Page #{page}/#{images['pages']}", total: PER_PAGE) images.each { |photoset| get_photo(photoset['id']); pb.increment } rescue StandardError => e retry_count += 1 sleep(30.seconds) retry unless retry_count == MAX_RETRIES puts "Failure on page #{page}" end break if images.nil? || images.size < PER_PAGE end end |