Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walker's next() needs to handle empty page returned from Flickr service #100

Open
chcao052 opened this issue Sep 18, 2018 · 0 comments
Open

Comments

@chcao052
Copy link

chcao052 commented Sep 18, 2018

I am not sure why Flickr service returns multiple empty pages inside next() with the following code.

w = flickr_api.Walker(flickr_api.Photo.search, text="sydney night", license="8,9,10", media="photos")
for i, photo in enumerate(w):
     <download the photo>

It crashed due to accessing empty list at around photo 728
Here is my fix:

  def next(self):
        if self._curr_index == len(self._curr_list):
            if self._page < self._info.pages:
                while self._page < self._info.pages:
                    self._page += 1
                    self.kwargs["page"] = self._page
                    self._curr_list = self.method(*self.args, **self.kwargs)
                    self._info = self._curr_list.info
                    self._curr_index = 0
                    if len(self._curr_list) == 0:
                        continue        # here
                    break
                if len(self._curr_list) == 0:
                    raise StopIteration()
            else:
                raise StopIteration()
        curr = self._curr_list[self._curr_index]
        self._curr_index += 1
        return curr
@chcao052 chcao052 changed the title Walker's next() need to handle empty page Walker's next() needs to handle empty page Sep 18, 2018
@chcao052 chcao052 changed the title Walker's next() needs to handle empty page Walker's next() needs to handle empty page returned from Flickr service Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant