def _fetch_file()

in spotify_tensorflow/luigi/utils.py [0:0]


def _fetch_file(url, output_path=None):
    # type: (str, str) -> str
    """Fetches a file from the url and saves it to a temp file (or at the provided output path)."""
    rep = requests.get(url, allow_redirects=True)
    if rep.status_code / 100 != 2:
        raise Exception("Got [status_code:{}] fetching file at [url:{}]".format(rep.status_code,
                                                                                url))

    if output_path is None:
        output_path = tempfile.NamedTemporaryFile(delete=False).name

    with open(output_path, "wb") as out:
        out.write(rep.content)

    return output_path