-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload_Hydroweb_data.py
More file actions
58 lines (48 loc) · 2.64 KB
/
Download_Hydroweb_data.py
File metadata and controls
58 lines (48 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This file is the new script to download data for Hydroweb (https://hydroweb.next.theia-land.fr/)
help_message = """
Download products from your hydroweb.next projects (https://hydroweb.next.theia-land.fr) using the py-hydroweb lib (https://pypi.org/project/py-hydroweb/)
This script is an example tuned for your last hydroweb.next project but feel free to adapt it for future requests.
Follow these steps:
1. If not already done, install py-hydroweb latest version using `pip install -U py-hydroweb` (WARNING: python >= 3.8 is required)
2a. Generate an API-Key from hydroweb.next portal in your user settings
2b. Carefully store your API-Key (2 options):
- either in an environment variable `export HYDROWEB_API_KEY="<your_key_here>"`
- or in below script by replacing <your_key_here>
3. You can change download directory by adding an `output_folder` parameter when calling `submit_and_download_zip` (see below). By default, current path is used.
4. You are all set, run this script `python download_script.py`
For more documentation about how to use the py-hydroweb lib, please refer to https://pypi.org/project/py-hydroweb/.
"""
import logging
import sys
from datetime import datetime
from importlib.metadata import version
try:
import py_hydroweb
except ImportError:
print(help_message)
exit(1)
# Check py-hydroweb version
latest_version = "1.0.2"
if version("py_hydroweb") < latest_version:
logging.getLogger().warning(f"""\033[33m
/!\ Consider upgrading py-hydroweb to {latest_version} using `pip install -U py-hydroweb`
\033[0m""")
# Set log config
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
# Create a client
# - either using the API-Key environment variable (HYDROWEB_API_KEY)
#client: py_hydroweb.Client = py_hydroweb.Client("https://hydroweb.next.theia-land.fr/api")
# - or explicitly giving API-Key (comment line above and uncomment line below)
client: py_hydroweb.Client = py_hydroweb.Client("https://hydroweb.next.theia-land.fr/api", api_key=" ")# api key insert here
# Initiate a new download basket (input the name you want here)
basket: py_hydroweb.DownloadBasket = py_hydroweb.DownloadBasket("my_download_basket")
#bbox=[min_lon, min_lat, max_lon, max_lat]
# Niger: -15, 2, 15, 20
# Add collections in our basket
basket.add_collection("HYDROWEB_RIVERS_OPE", bbox=[-15, 2, 15, 20]) # "HYDROWEB_RIVERS_OPE" is the identifier for the data we want from https://hydroweb.next.theia-land.fr/
# Do download (input the archive name you want here, and optionally an output folder)
now = datetime.today().strftime("%Y%m%dT%H%M%S")
downloaded_zip_path: str = client.submit_and_download_zip(
basket,
zip_filename=f"my_hydroweb_data_{now}.zip"
)