From 825d3e84d228468020fac806fcbca59b3d06ef13 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 22 Feb 2023 14:12:26 +0100 Subject: [PATCH] replace progressbar by tqdm --- envs/environment.yaml | 1 - scripts/_helpers.py | 21 ++++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/envs/environment.yaml b/envs/environment.yaml index 9325ac09..5ffe0d71 100644 --- a/envs/environment.yaml +++ b/envs/environment.yaml @@ -33,7 +33,6 @@ dependencies: - networkx - scipy - shapely>=2.0 -- progressbar2 - pyomo - matplotlib<3.6 - proj diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 5032cdf9..634cc59b 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -4,7 +4,8 @@ # SPDX-License-Identifier: MIT from pathlib import Path - +import urllib +from tqdm import tqdm import pandas as pd REGION_COLS = ["geometry", "name", "x", "y", "country"] @@ -251,16 +252,14 @@ def aggregate_costs(n, flatten=False, opts=None, existing_only=False): def progress_retrieve(url, file): - import urllib - - from progressbar import ProgressBar - - pbar = ProgressBar(0, 100) - - def dlProgress(count, blockSize, totalSize): - pbar.update(int(count * blockSize * 100 / totalSize)) - - urllib.request.urlretrieve(url, file, reporthook=dlProgress) + + with tqdm(unit='B', unit_scale=True, unit_divisor=1024, miniters=1, position=0, leave=True) as t: + def update_to(b=1, bsize=1, tsize=None): + if tsize is not None: + t.total = tsize + t.update(b * bsize - t.n) + + urllib.request.urlretrieve(url, file, reporthook=update_to) def get_aggregation_strategies(aggregation_strategies):