def paginated_search(self, page=1, page_handler=None,
            max_pages=None, **kwargs):

        """Issue search with AppClient up to max_pages.
        For kwargs requirements, see docs for birdy AppClient."""
        if max_pages is None:
            max_pages = self.default_max_pages

        response = self.query(**kwargs)

        if page_handler:
            has_next_page = page_handler(response)

        if page < max_pages and has_next_page:
            try:
                kwargs.update({ k:v for k,v in urlparse.parse_qsl(
                    response.data.search_metadata.next_results[1:]) })
                if int(kwargs['max_id']) > int(kwargs.get('since_id',0)):
                    # logging.debug('Paginating query: %s' % str(kwargs))
                    self.paginated_search(page=page+1,
                            page_handler=page_handler,
                            max_pages=max_pages, **kwargs)

            except __HOLE__:
                try:
                    kwargs['max_id'] = str(response.data[-1]["id"])
                    # logging.debug('Paginating query: %s' % str(kwargs))
                    self.paginated_search(page=page+1,
                            page_handler=page_handler,
                            max_pages=max_pages, **kwargs)
                except (IndexError, TypeError):
                    logging.debug('error paging, so stop')

        else:
            # logging.debug('reached max pages or told no next page, so stop')
            pass
        return response
dataset/ETHPy150Open Impactstory/total-impact-webapp/totalimpactwebapp/twitter_paging.py/TwitterPager.paginated_search