Skip to content

Commit

Permalink
Some updates for compatibility with cdsapi = 0.7.4.
Browse files Browse the repository at this point in the history
The behaviour of the current `Client` is apparently unstable according
to ecmwf-projects/cads-api-client#94.
  • Loading branch information
Holmgren825 committed Nov 15, 2024
1 parent b1ea30d commit fae3d4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion cdsapi_helper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ def download_cds(
# Should go back up to download_request.
continue
# Everything is in the queue.
elif (df.state == "queued").any():
elif (
(df.state == "queued").any()
or (df.state == "running").any()
or (df.state == "accepted").any()
):
# Wait 30 minutes before checking the status again.
click.echo("Requests are running, waiting 30 min.")
sleep(60 * 30)
else:
check_request_again = False
Expand Down
14 changes: 7 additions & 7 deletions cdsapi_helper/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def update_request(dry_run: bool) -> None:
):
try:
if not dry_run:
result = cdsapi.api.Result(
client, {"request_id": request.request_id}
)
result = client.client.get_remote(request.request_id)
result.update()
df.at[request.Index, "state"] = result.reply["state"]
except HTTPError:
except HTTPError as err:
print(f"Request {request.Index} not found")
print(err)
df.at[request.Index, "state"] = "deleted"

df.to_csv("./cds_requests.csv")
Expand Down Expand Up @@ -95,22 +94,23 @@ def download_request(

def download_helper(
request: pd.core.frame.pandas,
filename_spec,
filename_spec: list,
client: cdsapi.Client,
dry_run: bool = False,
) -> str:
if request.state == "completed":
try:
result = cdsapi.api.Result(client, {"request_id": request.request_id})
result = client.client.get_remote(request.request_id)
result.update()
filename = build_filename(request, filename_spec)
if not dry_run:
result.download(filename)
return "downloaded"
else:
return request.state
except HTTPError:
except HTTPError as e:
print("Request not found")
print(e)
return request.state
else:
# No change to state.
Expand Down
2 changes: 1 addition & 1 deletion cdsapi_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def request_to_df(request: dict, reply: dict, req_hash: str) -> pd.DataFrame:


def build_filename(request: dict, filename_spec: list) -> str:
filetype = ".nc" if request.format == "netcdf" else ".grib"
filetype = ".nc" if request.data_format == "netcdf" else ".grib"
filename_parts = []
for var in filename_spec:
part = str_to_list(getattr(request, var))
Expand Down

0 comments on commit fae3d4e

Please sign in to comment.