from datetime import datetime


async def get_user_email(gh, user):
    """
    Given a username, get the correct email based on creation date
    """
    response = await gh.getitem(f"https://api.github.com/users/{user}")
    created_at = datetime.strptime(response["created_at"].split("T", 1)[0], "%Y-%m-%d")
    split = datetime.strptime("2017-07-18", "%Y-%m-%d")
    if created_at > split:
        email = f"{response['id']}+{user}@users.noreply.github.com"
    else:
        email = f"{user}@users.noreply.github.com"
    return email