|
368 | 368 | "def get_data_from_dataverse(data):\n", |
369 | 369 | " file_url = data.get(\"url\")\n", |
370 | 370 | " name_file = data.get(\"name_file\")\n", |
371 | | - " resp = requests.get(file_url)\n", |
372 | | - " with open(name_file, \"wb\") as f:\n", |
373 | | - " f.write(resp.content)\n", |
| 371 | + " if not file_url or not name_file:\n", |
| 372 | + " raise ValueError(\"Missing 'url' or 'name_file' in data\")\n", |
| 373 | + "\n", |
| 374 | + " path = Path(name_file)\n", |
| 375 | + "\n", |
| 376 | + " if path.exists():\n", |
| 377 | + " print(f\"skipping {name_file} (already exists)\\n\")\n", |
| 378 | + " return str(path)\n", |
| 379 | + "\n", |
| 380 | + " resp = requests.get(file_url, stream=True, timeout=60)\n", |
| 381 | + " resp.raise_for_status()\n", |
| 382 | + "\n", |
| 383 | + " with open(path, \"wb\") as f:\n", |
| 384 | + " print(f\"Downloading {name_file}\\n\")\n", |
| 385 | + " for chunk in resp.iter_content(chunk_size=1024 * 1024):\n", |
| 386 | + " if chunk:\n", |
| 387 | + " f.write(chunk)\n", |
| 388 | + "\n", |
| 389 | + " return str(path)\n", |
374 | 390 | "\n", |
375 | 391 | "\n", |
376 | 392 | "print(\"Your download is starting...\")\n", |
|
1133 | 1149 | ], |
1134 | 1150 | "metadata": { |
1135 | 1151 | "kernelspec": { |
1136 | | - "display_name": "Python 3 (ipykernel)", |
| 1152 | + "display_name": "NSDF-Tutorial", |
1137 | 1153 | "language": "python", |
1138 | 1154 | "name": "python3" |
1139 | 1155 | }, |
|
1148 | 1164 | "nbconvert_exporter": "python", |
1149 | 1165 | "pygments_lexer": "ipython3", |
1150 | 1166 | "version": "3.10.14" |
1151 | | - }, |
1152 | | - "vscode": { |
1153 | | - "interpreter": { |
1154 | | - "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" |
1155 | | - } |
1156 | 1167 | } |
1157 | 1168 | }, |
1158 | 1169 | "nbformat": 4, |
|
0 commit comments