from bs4 import BeautifulSoup


def get_valid_urls(category_page: BeautifulSoup):
    """
    Gets all valid urls from a category page

    input:
        :param: url: category_page
    returns:
        - valid_urls: list of all valid article urls on a given category page
    """

    base_url = "https://www.bbc.com"

    all_urls = category_page.findAll("a")
    valid_article_urls = []
    for url in all_urls:

        href = url.get("href")
        if (
            href.startswith("/pidgin/tori")
            or href.startswith("/pidgin/world")
            or href.startswith("/pidgin/sport")
        ) and href[-1].isdigit():
            complete_href = f"{base_url}{href}"
            valid_article_urls.append(complete_href)

        # from a look at BBC pidgin's urls, they always begin with the following strings.
        # so we obtain valid article urls using these strings
    return list(set(valid_article_urls))