from bs4 import BeautifulSoup


def parse_response(response):
    """
    Convert a valid response form the https://www.myshiptracking.com/vessels/ website
    into a dictionary containing the information parsed from the 'vessels_table2'

    :param response:
    :return: dict
    """
    soup = BeautifulSoup(response.text, "html.parser")

    tables = soup.find_all("table", {"class": "vessels_table2"})

    data = []
    for table in tables:
        rows = table.findAll(lambda tag: tag.name == "tr")
        for row in rows:
            cols = row.find_all("td")
            cols = [ele.text.strip() for ele in cols]
            data.append([ele for ele in cols if ele])

    ans = {x[0]: x[1] for x in data if len(x) == 2}

    return ans