|
6 | 6 | from tqdm import tqdm |
7 | 7 | from SPARQLWrapper import SPARQLWrapper, JSON |
8 | 8 | from hashlib import sha256 |
| 9 | +import os |
9 | 10 |
|
10 | 11 | __debug = False |
11 | 12 |
|
@@ -399,13 +400,15 @@ def __download_file__(url, filename): |
399 | 400 | - url: the URL of the file to download |
400 | 401 | - filename: the local file path where the file should be saved |
401 | 402 | """ |
402 | | - print("download "+url) |
| 403 | + |
| 404 | + print("download "+url) |
| 405 | + os.makedirs(os.path.dirname(filename), exist_ok=True) # Create the necessary directories |
403 | 406 | response = requests.get(url, stream=True) |
404 | 407 | total_size_in_bytes= int(response.headers.get('content-length', 0)) |
405 | 408 | block_size = 1024 # 1 Kibibyte |
406 | 409 |
|
407 | 410 | progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True) |
408 | | - with open(filename, 'wb') as file: |
| 411 | + with open(filename, 'wb') as file: |
409 | 412 | for data in response.iter_content(block_size): |
410 | 413 | progress_bar.update(len(data)) |
411 | 414 | file.write(data) |
@@ -473,11 +476,11 @@ def download( |
473 | 476 | # dataID or databus collection |
474 | 477 | if databusURI.startswith("http://") or databusURI.startswith("https://"): |
475 | 478 | # databus collection |
476 | | - if "/collections/" in databusURI: |
| 479 | + if "/collections/" in databusURI: #TODO "in" is not safe! there could be an artifact named collections, need to check for the correct part position in the URI |
477 | 480 | query = __handle_databus_collection__(endpoint,databusURI) |
478 | 481 | res = __handle__databus_file_query__(endpoint, query) |
479 | 482 | else: |
480 | | - print("dataId not supported yet") |
| 483 | + print("dataId not supported yet") #TODO add support for other DatabusIds here (artifact, group, etc.) |
481 | 484 | # query in local file |
482 | 485 | elif databusURI.startswith("file://"): |
483 | 486 | print("query in file not supported yet") |
|
0 commit comments