Beispiel #1
0
  def fetch_page_title(self, page_id):
    """Returns the page title corresponding to the provided page ID.

    Args:
      page_id: The page ID whose ID to fetch.

    Returns:
      str: The page title corresponding to the provided page ID.

    Raises:
      ValueError: If the provided page ID is invalid or does not exist.
    """
    helpers.validate_page_id(page_id)

    query = 'SELECT title FROM pages WHERE id = ?;'
    query_bindings = (page_id,)
    self.sdow_cursor.execute(query, query_bindings)

    page_title = self.sdow_cursor.fetchone()

    if not page_title:
      raise ValueError(
          'Invalid page ID "{0}" provided. Page ID does not exist.'.format(page_id))

    return page_title[0].encode('utf-8').replace('_', ' ')
Beispiel #2
0
  def fetch_page_title(self, page_id):
    """Returns the page title corresponding to the provided page ID.

    Args:
      page_id: The page ID whose ID to fetch.

    Returns:
      str: The page title corresponding to the provided page ID.

    Raises:
      ValueError: If the provided page ID is invalid or does not exist.
    """
    helpers.validate_page_id(page_id)

    query = 'SELECT title FROM pages WHERE id = ?;'
    query_bindings = (page_id,)
    self.cursor.execute(query, query_bindings)

    page_title = self.cursor.fetchone()

    if not page_title:
      raise ValueError(
          'Invalid page ID "{0}" provided. Page ID does not exist.'.format(page_id))

    return page_title[0].encode('utf-8').replace('_', ' ')
Beispiel #3
0
    def compute_shortest_paths(self, source_page_id, target_page_id):
        """Returns a list of page IDs indicating the shortest path between the source and target pages.
    Note: the provided page IDs must correspond to non-redirect pages, but that check is not made
    for performance reasons.
    Args:
      source_page_id: The ID corresponding to the page at which to start the search.
      target_page_id: The ID corresponding to the page at which to end the search.
    Returns:
      list(list(int)): A list of integer lists corresponding to the page IDs indicating the shortest path
        between the source and target page IDs.
    Raises:
      ValueError: If either of the provided page IDs are invalid.
    """
        helpers.validate_page_id(source_page_id)
        helpers.validate_page_id(target_page_id)

        return breadth_first_search(source_page_id, target_page_id, self)
Beispiel #4
0
  def compute_shortest_paths(self, source_page_id, target_page_id):
    """Returns a list of page IDs indicating the shortest path between the source and target pages.

    Note: the provided page IDs must correspond to non-redirect pages, but that check is not made
    for performance reasons.

    Args:
      source_page_id: The ID corresponding to the page at which to start the search.
      target_page_id: The ID corresponding to the page at which to end the search.

    Returns:
      list(list(int)): A list of integer lists corresponding to the page IDs indicating the shortest path
        between the source and target page IDs.

    Raises:
      ValueError: If either of the provided page IDs are invalid.
    """
    helpers.validate_page_id(source_page_id)
    helpers.validate_page_id(target_page_id)

    return breadth_first_search(source_page_id, target_page_id, self)