diff --git a/Project.toml b/Project.toml index 67f5e7d..e30f5c4 100644 --- a/Project.toml +++ b/Project.toml @@ -4,10 +4,12 @@ authors = ["Micky Yun Chan and contributors"] version = "2.0.3" [deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" [compat] +Dates = "1.11" HTTP = "1" JSON = "0.21" julia = "1" diff --git a/src/CDSAPI.jl b/src/CDSAPI.jl index 9f84818..24d3a3d 100644 --- a/src/CDSAPI.jl +++ b/src/CDSAPI.jl @@ -2,6 +2,7 @@ module CDSAPI using HTTP using JSON +using Dates """ retrieve(name, params, filename; wait=1.0) @@ -52,12 +53,17 @@ function retrieve(name, params::AbstractDict, filename; wait=1.0) data = JSON.parse(String(response.body)) endpoint = Dict(response.headers)["location"] + laststatus = nothing while data["status"] != "successful" data = HTTP.request("GET", endpoint, ["PRIVATE-TOKEN" => creds["key"]] ) data = JSON.parse(String(data.body)) - @info "CDS request" dataset=name status=data["status"] + + if data["status"] != laststatus + @info "CDS request update on $(now())" dataset = name status = data["status"] + laststatus = data["status"] + end if data["status"] == "failed" throw(ErrorException(""" @@ -78,6 +84,7 @@ function retrieve(name, params::AbstractDict, filename; wait=1.0) ["PRIVATE-TOKEN" => creds["key"]] ) body = JSON.parse(String(response.body)) + HTTP.download(body["asset"]["value"]["href"], filename) return data