How to use the numerapi.utils.download_file function in numerapi

To help you get started, we’ve selected a few numerapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uuazed / numerapi / tests / test_utils.py View on Github external
def test_download_file(tmpdir):
    url = "https://someurl"
    responses.add(responses.GET, url)

    # convert to string to make python<3.6 happy
    path = str(tmpdir.join("somefilepath"))
    utils.download_file("https://someurl", path)
    assert os.path.exists(path)
github uuazed / numerapi / numerapi / numerapi.py View on Github external
dest_filename = "numerai_dataset_{0}.zip".format(round_number)
        else:
            # ensure it ends with ".zip"
            if unzip and not dest_filename.endswith(".zip"):
                dest_filename += ".zip"
        dataset_path = os.path.join(dest_path, dest_filename)

        if os.path.exists(dataset_path):
            self.logger.info("target file already exists")
            return dataset_path

        # create parent folder if necessary
        utils.ensure_directory_exists(dest_path)

        url = self.get_dataset_url(tournament)
        utils.download_file(url, dataset_path, self.show_progress_bars)

        # unzip dataset
        if unzip:
            # remove the ".zip" in the end
            dataset_name = dest_filename[:-4]
            self._unzip_file(dataset_path, dest_path, dataset_name)

        return dataset_path
github numerai / numerox / numerox / numerai.py View on Github external
If download fails then retry download `n_tries` times, pausing
    `sleep_seconds` between each try.

    Unlike nx.download() this function loads and returns the data object.
    """
    # line below expands e.g. ~/tmp to /home/me/tmp...
    filename = os.path.expanduser(filename)
    count = 0
    while count < n_tries:
        try:
            if verbose:
                print("Download dataset {}".format(filename))
            napi = NumerAPI()
            url = napi.get_dataset_url(tournament=8)
            download_file(url, filename)
            break
        except:  # noqa
            print('download failed')
            time.sleep(sleep_seconds)
        count += 1
    if load:
        data = nx.load_zip(filename,
                           verbose=verbose,
                           include_train=include_train,
                           single_precision=single_precision)
    else:
        data = None
    return data