Download a file from a URL to a local path. If the file already exists, it will not be downloaded again. output_file_path is the local path to save the downloaded file. If not provided, the file will be saved in the root directory. Returns the local path of the downloaded file.
(url: str, output_file_path: str | None = None)
| 535 | |
| 536 | |
| 537 | def download_file(url: str, output_file_path: str | None = None) -> str: |
| 538 | """ |
| 539 | Download a file from a URL to a local path. If the file already exists, it will not be downloaded again. |
| 540 | |
| 541 | output_file_path is the local path to save the downloaded file. If not provided, the file will be saved in the root directory. |
| 542 | |
| 543 | Returns the local path of the downloaded file. |
| 544 | """ |
| 545 | file_name = url.split('/').pop() |
| 546 | output_file = f'./tmp/{file_name}' if output_file_path is None else output_file_path |
| 547 | if not os.path.exists(output_file): |
| 548 | print(f"Downloading {url} to {output_file}") |
| 549 | wget.download(url, out=output_file) |
| 550 | print(f"Done downloading to {output_file}") |
| 551 | else: |
| 552 | print(f"File already exists at {output_file}") |
| 553 | return output_file |
| 554 | |
| 555 | |
| 556 | def is_slow_test_allowed(): |