import aiohttp


async def get(url, indicator):
    """
    A simple async get function, tailored to tracking failures

    Parameters
    ----------
    url : str
        The URL to make a request to
    indicator : str
        The name of the indicator being retrieved (to make tracking easier)
    Returns
    -------
    IF request fails, returns
    indicator : str
        The same indicator name, so the request can be retried later
    ELSE
    {indicator : resp}: dict(str: response}
        The indicator and the HTTP response from the request
    """
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(url=url) as response:
                resp = await response.read()
                if len(resp) > 0:
                    print(f'Successfully got url {url} with response of length {len(resp)}.')
                    return {indicator:resp}
                else:
                    print(f'Response for url {url} was of length 0')
                    return indicator
    except Exception as e:
        print(f'Unable to get url {url} due to {e.__class__}.')
        return indicator