import requests
from bs4 import BeautifulSoup


def get_license_dates(licDetailURL):
    """
    Get various dates (grant date, expiry date, effective date, cancel date) associated with a license
    :param licDetailURL: License URL
    :return: Dates associated with the license
    """
    resp = requests.get(licDetailURL)
    soup = BeautifulSoup(resp.text, features="lxml")
    keys = soup.find_all('b')
    grant_date = None
    effective_date = None
    cancel_date = None
    exp_date = None
    for key in keys:
        if key.text.find('Dates') != -1:
            grant_key = key.findNext('td').findNext('td')
            grant_date = grant_key.text.strip()
            exp_key = grant_key.findNext('td').findNext('td')
            exp_date = exp_key.text.strip()
            effective_key = exp_key.findNext('td').findNext('td')
            effective_date = effective_key.text.strip()
            cancel_key = effective_key.findNext('td').findNext('td')
            cancel_date = cancel_key.text.strip()
            break
    return grant_date, effective_date, cancel_date, exp_date