|
4 | 4 |
|
5 | 5 | import os |
6 | 6 |
|
7 | | -# import io |
8 | | - |
9 | | -# import compas |
10 | | - |
11 | 7 | try: |
12 | | - # from urllib.request import urlopen |
13 | 8 | from urllib.request import urlretrieve |
14 | 9 | except ImportError: |
15 | | - # from urllib2 import urlopen |
16 | 10 | from urllib import urlretrieve |
17 | 11 |
|
18 | | -# try: |
19 | | -# from PIL import Image |
20 | | -# except ImportError: |
21 | | -# if compas.is_windows(): |
22 | | -# compas.raise_if_not_ironpython() |
23 | | -# elif not compas.is_mono(): |
24 | | -# raise |
25 | | - |
26 | 12 |
|
27 | 13 | def download_file_from_remote(source, target, overwrite=True): |
28 | 14 | """Download a file from a remote source and save it to a local destination. |
@@ -66,41 +52,3 @@ def download_file_from_remote(source, target, overwrite=True): |
66 | 52 | else: |
67 | 53 | if overwrite: |
68 | 54 | urlretrieve(source, target) |
69 | | - |
70 | | - |
71 | | -# def download_image_from_remote(source, target, show=False): |
72 | | -# """Download an image from a remote source and save it to a local destination. |
73 | | - |
74 | | -# Parameters |
75 | | -# ---------- |
76 | | -# source : str |
77 | | -# The url of the source file. |
78 | | -# target : str |
79 | | -# The path of the local destination. |
80 | | -# show : bool, optional |
81 | | -# Show the downloaded image. |
82 | | -# Default is ``False`` |
83 | | - |
84 | | -# Examples |
85 | | -# -------- |
86 | | -# .. code-block:: python |
87 | | - |
88 | | -# import os |
89 | | -# import compas |
90 | | -# from compas.utilities.remote import download_image_from_remote |
91 | | - |
92 | | -# source = 'http://block.arch.ethz.ch/brg/images/cache/dsc02360_ni-2_cropped_1528706473_624x351.jpg' |
93 | | -# target = os.path.join(compas.APPDATA, 'data', 'theblock.jpg') |
94 | | - |
95 | | -# download_image_from_remote(source, target, show=True) |
96 | | - |
97 | | -# """ |
98 | | -# # response = requests.get(source) |
99 | | -# # response.raise_for_status() |
100 | | - |
101 | | -# response = urlopen(source) |
102 | | -# image = Image.open(io.BytesIO(response.read())) |
103 | | - |
104 | | -# if show: |
105 | | -# image.show() |
106 | | -# image.save(target) |
0 commit comments