Find the number of pages paginating a genre's letter URL
175192
def _find_num_pages(self, url):
    
    def _new_url(i):
      return '{}&page={}#page'.format(url, i)
    i = 0
    j = 2000
    k = (i + j) / 2
    crawler = SeriesCrawler(_new_url(k))
    while i < j:
      ids = crawler.get_ids()
      # If we only find one (we've gone too far)
      if len(ids) == 1:
        # Don't decrement by 1 b/c this could be the last page
        j = k
        k = (i + j) / 2
        crawler.set_url(_new_url(k))
      else:
        i = k + 1
        k = (i + j) / 2
        crawler.set_url(_new_url(k))
    return i
73142
def expand_pagination(pages):
    """"""
    # If there is no hyphen, it's a single page, and we're good to go
    parts = pages.split('-')
    if len(parts) == 1: # No hyphen, so no split
        return pages
    elif len(parts) == 2:
        start = parts[0]
        end = parts[1]
        # If the end is the same number of digits as the start, then we
        # don't change anything!
        if len(start) == len(end):
            return pages
        # Otherwise, replace the last digits of start with the digits of end
        num_end_digits = len(end)
        new_end = start[:-num_end_digits] + end
        return '%s-%s' % (start, new_end)
    else: # More than one hyphen, something weird happened
        logger.warning("Multiple hyphens in page number: %s" % pages)
        return pages
1309392
def list_records_next_page(self):
        
        uri = self._paging.get("record", {}).get("next_uri")
        if uri is None:
            raise exc.NoMoreResults("There are no more pages of records to list.")
        return self._list_records(uri)
669930
def pages_counter(self, total: int, page_size: int = 100) -> int:
        
        if total <= page_size:
            count_pages = 1
        else:
            if (total % page_size) == 0:
                count_pages = total / page_size
            else:
                count_pages = (total / page_size) + 1
        # method ending
        return int(count_pages)
839975
def to_find(self):
        '''
        
        '''
        kwd = {'pager': ''}
        self.render('user/info_list/most.html',
                    topmenu='',
                    userinfo=self.userinfo,
                    kwd=kwd)
294827
def get_page(self, paginator):
        """"""
        page = int(self.get_and_save_value('page', 1))
        if page < 1:
            return self.save_value('page', 1)

        if page > paginator.num_pages:
            return self.save_value('page', paginator.num_pages)
        return page
884721
def get_all_letters(self, params=None):
        
        if not params:
            params = {}
        return self._iterate_through_pages(self.get_letters_per_page, resource=LETTERS, **{'params': params})
69933
def paging
      page = 0
      results = []
      loop do
        page += 1
        current = yield(page)

        results += current

        break if (current || []).count < page_size # no more results
      end

      return results
    end
261521
def get_paginated_urlargs(self):
        
        position = self.get_paginated_position()
        
        if not position:
            return '#forum-post-{0}'.format(self.id)
        
        return '?page={0}#forum-post-{1}'.format(position, self.id)
653952
def _previous_pages_count(self):
        ''
        skip = self.skip
        if skip == 0:
            return 0
        count, remainder = divmod(skip, self.limit)
        return count
1181578
def __total_pages(self) -> int:
        
        row_count = self.model.query.count()
        if isinstance(row_count, int):
            return int(row_count / self.limit)
        return None
1185285
function (pageNum) {
            var textPath = util.template(config.template.html, { page: pageNum });
            return config.url + textPath + config.queryString;
        }
467655
def extract_pagination_links(self, response):
        ''''''
        try:
            link_header = response.headers['Link']
        except KeyError:
            logger.warn('Unable to find the Link header. Unable to continue with pagination.')
            return None

        split_header = link_header.split(',')
        exploded_split_header = [i.split(';') for i in split_header]

        pagination_links = {}
        for h in exploded_split_header:
            link = h[0]
            rel = h[1]
            # Check that the link format is what we expect
            if link.startswith('<') and link.endswith('>'):
                link = link[1:-1]
            else:
                continue
            # Extract the rel argument
            m = self.rel_matcher.match(rel)
            try:
                rel = m.groups()[0]
            except AttributeError:
                # Match returned None, just skip.
                continue
            except IndexError:
                # Matched but no groups returned
                continue

            pagination_links[rel] = link
        return pagination_links
1084315
def page_count(self):
        
        postcount = self.post_set.count()
        max_pages = (postcount / get_paginate_by())
        if postcount % get_paginate_by() != 0:
            max_pages += 1
        return max_pages
1284429
def paginate(idx, max, url, &b)
      return '' if max == 0
      url = url.gsub(%r{^/?(.*?)/?$}, '\1')
      b ||= lambda{}
      link = lambda {|*args|
        i, title, text = args
        "<a href=\"/#{url}/#{i}#{'?' + @query_string if @query_string}\" " +
         "#{'onclick="return false;"' if (i == idx)} " +
         "class=\"#{'disabled ' if (i == idx)}#{b.call(i)}\" " +
         "title=\"#{title||"Go to page #{i}"}\">#{text||i}</a>"
      }
      res = '<div class="nav">'
      if (idx > 0)
        res << link.call(idx - 1, "Go to previous page", "&#171; Previous")
      else
        res << "<a href=\"/#{url}/0\" onclick=\"return false;\" " +
                "class=\"disabled\" title=\"Disabled\">&#171; Previous</a>"
      end
      if idx < 10
        idx.times {|i| res << link.call(i)}
      else
        (0..2).each {|i| res << link.call(i)}
        res << '&nbsp;&#8230;&nbsp;'
        ((idx-4)...idx).each {|i| res << link.call(i)}
      end
      res << link.call(idx, 'Current Page')
      if idx > (max - 10)
        ((idx+1)...max).each {|i| res << link.call(i)}
      else
        ((idx+1)..(idx+4)).each {|i| res << link.call(i)}
        res << '&nbsp;&#8230;&nbsp;'
        ((max-3)...max).each {|i| res << link.call(i)}
      end
      if (idx < (max - 1))
        res << link.call(idx + 1, "Go to next page", "Next &#187;")
      else
        res << "<a href=\"/#{url}/#{max-1}\" onclick=\"return false;\" " +
                "class=\"disabled\" title=\"Disabled\"}\">Next &#187;</a>"
      end
      res << '</div>'
    end
33749
def next(self):
        """"""
        if self.iter == None:
            self.iter = iter(self.objs)
        try:
            return self.iter.next()
        except StopIteration:
            self.iter = None
            self.objs = []
            if int(self.page) < int(self.total_pages):
                self.page += 1
                self._connection.get_response(self.action, self.params, self.page, self)
                return self.next()
            else:
                raise
172969
def get_pages(url):
    
    while True:
        yield url
        doc = html.parse(url).find("body")
        links = [a for a in doc.findall(".//a") if a.text and a.text.startswith("next ")]
        if not links:
            break
        url = urljoin(url, links[0].get('href'))