Skip to content

Commit 7790d78

Browse files
committed
Refactor download_euroc.py
1 parent 9c97835 commit 7790d78

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

benchmark/scripts/download_euroc.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,36 @@
44
import urllib.request
55
import zipfile
66

7+
from tqdm import tqdm
78

8-
def download(src, dst):
9-
""" Download """
10-
if not os.path.exists(dst):
11-
print(f"Downloading [{src}] -> [{dst}]", flush=True)
12-
urllib.request.urlretrieve(src, dst)
13-
print("")
9+
10+
def download(url, save_path):
11+
# Get the size of the file first
12+
response = urllib.request.urlopen(url)
13+
total_size = int(response.info().get('Content-Length').strip())
14+
15+
# Initialize the progress bar
16+
pbar = tqdm(total=total_size, unit='B', unit_scale=True, desc=save_path)
17+
18+
try:
19+
# Open the URL and the output file
20+
response = urllib.request.urlopen(url)
21+
out_file = open(save_path, 'wb')
22+
23+
# Read and write the file in chunks
24+
chunk_size = 1024
25+
while True:
26+
chunk = response.read(chunk_size)
27+
if not chunk:
28+
break
29+
out_file.write(chunk)
30+
pbar.update(len(chunk))
31+
32+
finally:
33+
# Clean up: Close the file and the response
34+
pbar.close()
35+
out_file.close()
36+
response.close()
1437

1538

1639
def download_sequences(dst_dir):
@@ -108,5 +131,4 @@ def extract_zips(src_dir, dst):
108131
bag_dir = "./rosbags"
109132
# download_sequences(dst_dir)
110133
# extract_zips(dst_dir, ".")
111-
112134
download_rosbags(bag_dir)

0 commit comments

Comments
 (0)