Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/CDSAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ directory as `filename`.
The client periodically requests the status of the retrieve request.
`wait` is the maximum time (in seconds) between status updates.
"""
function retrieve(name, params, filename; wait=1.0)
function retrieve(name, params, filename; wait=1.0) end

function retrieve(name, params::AbstractDict, filename; wait=1.0)
creds = Dict()
open(joinpath(homedir(), ".cdsapirc")) do f
for line in readlines(f)
Expand All @@ -27,12 +29,12 @@ function retrieve(name, params, filename; wait=1.0)
["PRIVATE-TOKEN" => creds["key"]],
body=JSON.json(Dict("inputs" => params))
)
body = JSON.parse(String(response.body))
data = Dict("status" => "queued")

data = JSON.parse(String(response.body))
job_endpoint = Dict(response.headers)["location"]

while data["status"] != "successful"
data = HTTP.request("GET",
creds["url"] * "/retrieve/v1/jobs/" * string(body["jobID"]),
data = HTTP.request("GET", job_endpoint,
["PRIVATE-TOKEN" => creds["key"]]
)
data = JSON.parse(String(data.body))
Expand All @@ -53,7 +55,7 @@ function retrieve(name, params, filename; wait=1.0)
end

response = HTTP.request("GET",
creds["url"] * "/retrieve/v1/jobs/" * string(body["jobID"]) * "/results",
job_endpoint * "/results",
["PRIVATE-TOKEN" => creds["key"]]
)
body = JSON.parse(String(response.body))
Expand All @@ -62,6 +64,9 @@ function retrieve(name, params, filename; wait=1.0)
return data
end

retrieve(name, params::String, filename; wait=1.0) =
retrieve(name, JSON.parse(params), filename; wait)

"""
py2ju(dictstr)

Expand Down