import typing
import requests


def download_file_from_google_drive(
        gdrive_file_id: typing.AnyStr,
        destination: typing.AnyStr,
        chunk_size: int = 32768
) -> typing.AnyStr:
    """
    Downloads a file from google drive, bypassing the confirmation prompt.

    Args:
        gdrive_file_id: ID string of the file to download from google drive.
        destination: where to save the file.
        chunk_size: chunk size for gradual downloads.

    Returns:
        The path to the downloaded file.
    """
    # taken from this StackOverflow answer: https://stackoverflow.com/a/39225039
    URL = "https://docs.google.com/uc?export=download"
    session = requests.Session()
    response = session.get(URL, params={'id': gdrive_file_id}, stream=True)
    token = None
    for key, value in response.cookies.items():
        if key.startswith('download_warning'):
            token = value
    if token:
        params = {'id': gdrive_file_id, 'confirm': token}
        response = session.get(URL, params=params, stream=True)
    with open(destination, "wb") as f:
        for chunk in response.iter_content(chunk_size):
            if chunk:  # filter out keep-alive new chunks
                f.write(chunk)
    return destination