Skip to content

Commit 5196e19

Browse files
committed
Add progress bar to the download script
1 parent 4ec9c66 commit 5196e19

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/download.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
import requests
4+
from tqdm import tqdm
45

56
from src.config import Config
67

@@ -12,23 +13,24 @@
1213
base_url = f"https://pretalx.com/api/events/{Config.event}/"
1314

1415
resources = [
15-
# Questions needs to be passed to include answers in the same endpoint,
16+
# Questions need to be passed to include answers in the same endpoint,
1617
# saving us later time with joining the answers.
1718
"submissions?questions=all",
1819
"speakers?questions=all",
1920
]
2021

2122
for resource in resources:
22-
print("Downloading: ", resource)
2323
url = base_url + f"{resource}"
2424

2525
res0 = []
2626
data = {"next": url}
2727
n = 0
2828

29+
pbar = tqdm(desc=f"Downloading {resource}", unit=" page", dynamic_ncols=True)
30+
2931
while url := data["next"]:
3032
n += 1
31-
print(f"Page {n}")
33+
pbar.update(1)
3234
response = requests.get(url, headers=headers)
3335

3436
if response.status_code != 200:
@@ -37,6 +39,8 @@
3739
data = response.json()
3840
res0 += data["results"]
3941

42+
pbar.close()
43+
4044
filename = resource.split("?")[0] # To get rid of "?questions"
4145
filename = f"{filename}_latest.json"
4246
filepath = Config.raw_path / filename

0 commit comments

Comments
 (0)