forked from torch-points3d/torch-points3d
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathdownload.py
38 lines (29 loc) · 885 Bytes
/
download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import os.path as osp
from six.moves import urllib
import ssl
def download_url(url, folder, log=True):
r"""Downloads the content of an URL to a specific folder.
Args:
url (string): The url.
folder (string): The folder.
log (bool, optional): If :obj:`False`, will not print anything to the
console. (default: :obj:`True`)
"""
filename = url.rpartition("/")[2]
path = osp.join(folder, filename)
if osp.exists(path): # pragma: no cover
if log:
print("Using exist file", filename)
return path
if log:
print("Downloading", url)
try:
os.makedirs(folder)
except:
pass
context = ssl._create_unverified_context()
data = urllib.request.urlopen(url, context=context)
with open(path, "wb") as f:
f.write(data.read())
return path