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.search(**kwargs)

        if page_handler:
            page_handler(response)
        # if page < max_pages and \
        #         'next_results' in response.data.search_metadata:
        if max_pages < 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 AttributeError:
                try:
                    kwargs['since_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:
                    logging.debug('IndexError, so stop')

        else:
            logging.debug('reached max pages, so stop')
dataset/ETHPy150Open Impactstory/total-impact-core/totalimpact/providers/twitter_paging.py/TwitterPager.paginated_search/swapped operands of `<`