#!/usr/bin/env python3

import bs4

def get_universal_product_code(soup):
    """Analyze "soup" to extract universal product code (UPC).

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        book's UPC
    """
    table = soup.table
    cell = table.find_all("td")
    upc = cell[0].text

    return str(upc)

def get_title(soup):
    """ Analyze "soup" to extract book's title.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        book's title
    """
    title = soup.h1.text

    return str(title)

def get_price_including_tax(soup):
    """ Analyze "soup" to extract price with tax.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        price with tax
    """
    table = soup.table
    cell = table.find_all("td")
    price_including_tax = cell[3].text

    return price_including_tax

def get_price_excluding_tax(soup):
    """ Analyze "soup" to extract price without tax.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        price whitout tax
    """
    table = soup.table
    cell = table.find_all("td")
    price_excluding_tax = cell[2].text

    return price_excluding_tax

def get_number_available(soup):
    """ Analyze "soup" to extract stock's availability.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        stock's availability
    """
    table = soup.table
    cell = table.find_all("td")
    number_available = cell[5].text[10:-11]
  
    return int(number_available)

def get_product_description(soup):
    """ Analyze "soup" to extract product's description.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        product's description
    """
    article = soup.find("article", "product_page")
    product_description = article.find_all("p")[3].text

    return str(product_description)

def get_category(soup):
    """ Analyze "soup" to extract book's category.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        book's category
    """
    breadcrumb = soup.find("ul", {"class": "breadcrumb"})
    items = breadcrumb.find_all("li")
    category = items[2].a.text

    return str(category)

def get_review_rating(soup):
    """ Analyze "soup" to extract rating review.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        rating review
    """
    str_to_number = {"One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5}
    p = soup.find("p", {"class": "star-rating"})
    str_rating = p["class"][1]
    review_rating = str_to_number.get(str_rating, 0)

    return int(review_rating)

def get_image_url(soup):
    """ Analyze "soup" to extract cover page url.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        cover page url
    """
    base_url = "http://books.toscrape.com/"
    div = soup.find("div", {"id": "product_gallery"})
    relative_url = div.find("img").attrs["src"]
    relative_url = relative_url.replace("../../", "")
    image_url = base_url + relative_url

    return str(image_url)

#!/usr/bin/env python3

import bs4

def get_universal_product_code(soup):
    """Analyze "soup" to extract universal product code (UPC).

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        book's UPC
    """
    table = soup.table
    cell = table.find_all("td")
    upc = cell[0].text

    return str(upc)

def get_title(soup):
    """ Analyze "soup" to extract book's title.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        book's title
    """
    title = soup.h1.text

    return str(title)

def get_price_including_tax(soup):
    """ Analyze "soup" to extract price with tax.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        price with tax
    """
    table = soup.table
    cell = table.find_all("td")
    price_including_tax = cell[3].text

    return price_including_tax

def get_price_excluding_tax(soup):
    """ Analyze "soup" to extract price without tax.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        price whitout tax
    """
    table = soup.table
    cell = table.find_all("td")
    price_excluding_tax = cell[2].text

    return price_excluding_tax

def get_number_available(soup):
    """ Analyze "soup" to extract stock's availability.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        stock's availability
    """
    table = soup.table
    cell = table.find_all("td")
    number_available = cell[5].text[10:-11]
  
    return int(number_available)

def get_product_description(soup):
    """ Analyze "soup" to extract product's description.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        product's description
    """
    article = soup.find("article", "product_page")
    product_description = article.find_all("p")[3].text

    return str(product_description)

def get_category(soup):
    """ Analyze "soup" to extract book's category.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        book's category
    """
    breadcrumb = soup.find("ul", {"class": "breadcrumb"})
    items = breadcrumb.find_all("li")
    category = items[2].a.text

    return str(category)

def get_review_rating(soup):
    """ Analyze "soup" to extract rating review.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        rating review
    """
    str_to_number = {"One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5}
    p = soup.find("p", {"class": "star-rating"})
    str_rating = p["class"][1]
    review_rating = str_to_number.get(str_rating, 0)

    return int(review_rating)

def get_image_url(soup):
    """ Analyze "soup" to extract cover page url.

    Args:
      soup -- bs4.BeautifulSoup from http request of book url.
    Return:
        cover page url
    """
    base_url = "http://books.toscrape.com/"
    div = soup.find("div", {"id": "product_gallery"})
    relative_url = div.find("img").attrs["src"]
    relative_url = relative_url.replace("../../", "")
    image_url = base_url + relative_url

    return str(image_url)

#!/usr/bin/env python3 Analyze "soup" to extract universal product code (UPC).      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         book's UPC Analyze "soup" to extract book's title.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         book's title Analyze "soup" to extract price with tax.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         price with tax Analyze "soup" to extract price without tax.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         price whitout tax Analyze "soup" to extract stock's availability.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         stock's availability Analyze "soup" to extract product's description.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         product's description Analyze "soup" to extract book's category.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         book's category Analyze "soup" to extract rating review.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         rating review Analyze "soup" to extract cover page url.      Args:       soup -- bs4.BeautifulSoup from http request of book url.     Return:         cover page url