Skip to content

Commit

Permalink
doc: update doc and code example for getArchivefileUrls
Browse files Browse the repository at this point in the history
  • Loading branch information
kan-fu committed Jan 13, 2025
1 parent 195b139 commit 19448d2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ onc.downloadArchivefile("AXISQ6044PTZACCC8E334C53_20161201T000001.000Z.jpg", ove
You can use the method `downloadArchivefile()` as above to download individual files or the method `downloadDirectArchivefile()`
to download all the files that match your filters.

Alternatively, if you prefer using a download manager like [aria2](https://aria2.github.io/) or [Free Download Manager](https://www.freedownloadmanager.org/), `getArchivefileUrls` and `getArchivefileUrl` can return the download URLs of the archivefile
without downloading the files.

Check more on the _[archive file download methods guide](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#archive-file-download-methods)_
and _[code examples](https://oceannetworkscanada.github.io/api-python-client/Code_Examples/Download_Archived_Files.html)_.

Expand Down
56 changes: 55 additions & 1 deletion doc/source/Code_Examples/Download_Archived_Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ onc.getArchivefile(params)

## Download archived files that match the parameters

Download all "mat" files from a hydrophone at Straight of Georgia East (_locationCode_:"**SEVIP**") using the parameter above.
Download all "mat" files from a hydrophone at Straight of Georgia East (_locationCode_:"**SEVIP**").

```python
params = {
Expand All @@ -127,3 +127,57 @@ onc.downloadDirectArchivefile(params)
# onc.getDirectFiles(params)

```

## Download archived files using a download manager

Return the download URLs from a hydrophone at Straight of Georgia East (_locationCode_:"**SEVIP**").

```python
params = {
"deviceCategoryCode": "HYDROPHONE",
"locationCode": "SEVIP",
"extension": "mat",
"dateFrom": "2018-10-05T00:00:00.000Z",
"dateTo": "2018-10-05T00:10:00.000Z",
}

# print is necessary to render the newline character
print(onc.getArchivefileUrls(params, joinedWithNewline=True))
```

After running the code, a list of URLs will be printed.

```
https://data.oceannetworks.ca/api/archivefile/download?filename=ICLISTENHF1560_20181004T235903.000Z-spect.mat&token=Your_TOKEN
https://data.oceannetworks.ca/api/archivefile/download?filename=ICLISTENHF1560_20181005T000403.000Z-spect.mat&token=Your_TOKEN
https://data.oceannetworks.ca/api/archivefile/download?filename=ICLISTENHF1560_20181005T000903.000Z-spect.mat&token=Your_TOKEN
```

At this point, you can open your favorite download manager, paste the URLs, and start the download.
Most modern download managers support batch download, probably from a multi-line text input, the clipboard or a file.

Here is an example of using a popular open source download manager -- aria2.

### webui-aria2

[aria2](https://aria2.github.io/) is a lightweight multi-protocol & multi-source command-line download utility.
[webui-aria2](https://github.com/ziahamza/webui-aria2) is a web interface to interact with aria2.
Refer to the webui-aria2 [README](https://github.com/ziahamza/webui-aria2?tab=readme-ov-file#webui-aria2) file
for more information on how to use the tool.

1. Install aria2 by downloading it from the [release](https://github.com/aria2/aria2/releases)
(or use your package manager if you are on Linux), extract the zip file,
and start the server by running

```shell
./aria2c --enable-rpc --rpc-listen-all
```

2. Go to <https://ziahamza.github.io/webui-aria2> (or you can download this repository and open index.html
from docs folder), change "Enter the host" field to "localhost" in the setting, and save the settings.
Sometimes you need to also refresh the page.
![Aria2c host change.png](../_static/Code_Examples/webui-aria2c-host.png)

3. Click "Add" -> "By URIs" in the menu. Fill in the URLs and start the download.
You can also customize the download in the "Download settings" like changing the download directory.
![Aria2c add URLs.png](../_static/Code_Examples/webui-aria2c-add-uri.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 19448d2

Please sign in to comment.