| 1 |
""" |
| 2 |
================================== |
| 3 |
Exporting from existing RequestIDs |
| 4 |
================================== |
| 5 |
|
| 6 |
This example takes a RequestID of an already existing export request, prints |
| 7 |
the corresponding "Request URL" and downloads the available files. |
| 8 |
|
| 9 |
Note that you can also use RequestIDs from export requests, that were |
| 10 |
submitted using the JSOC website. |
| 11 |
""" |
| 12 |
|
| 13 |
from pathlib import Path |
| 14 |
|
| 15 |
import drms |
| 16 |
|
| 17 |
############################################################################### |
| 18 |
# First we will create a `drms.Client`, using the JSOC baseurl. |
| 19 |
|
| 20 |
client = drms.Client() |
| 21 |
|
| 22 |
# Export request ID |
| 23 |
request_id = "JSOC_20201101_198" |
| 24 |
|
| 25 |
# Querying the server using the entered RequestID. |
| 26 |
print(f"Looking up export request {request_id}...") |
| 27 |
result = client.export_from_id(request_id) |
| 28 |
|
| 29 |
# Print request URL and number of available files. |
| 30 |
print(f"\nRequest URL: {result.request_url}") |
| 31 |
print(f"{len(result.urls)} file(s) available for download.\n") |
| 32 |
|
| 33 |
# Create download directory if it does not exist yet. |
| 34 |
out_dir = Path("downloads") / request_id |
| 35 |
if not out_dir.exists(): |
| 36 |
Path(out_dir).mkdir(parents=True) |
| 37 |
|
| 38 |
# Download all available files. |
| 39 |
result.download(out_dir) |
| 40 |
print("Download finished.") |
| 41 |
print(f"\nDownload directory:\n {Path.resolve(out_dir)}\n") |