Class: Flickr::Downloader
- Inherits:
-
Object
- Object
- Flickr::Downloader
- Defined in:
- lib/flickr/downloader.rb
Constant Summary collapse
- MAX_RETRIES =
10
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
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 |
# File 'lib/flickr/downloader.rb', line 10 def download page = 0 per_page = 100 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: "Images Page #{page}") images.each do |photoset| get_photo(photoset['id']) pb.increment end rescue StandardError => e puts "Failed on #{page} exception: #{e.}" if retry_count.zero? retry_count += 1 sleep(1.minute) puts "Retry retry #{retry_count}/#{MAX_RETRIES}" retry unless retry_count == MAX_RETRIES end break if images.size < per_page end end |