Skip to content

Commit

Permalink
Merge pull request #21 from gdcc/v0p2p1a
Browse files Browse the repository at this point in the history
V0p2p1a
  • Loading branch information
gaelforget authored Sep 5, 2023
2 parents 992a722 + d4eea0c commit 86c4482
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Dataverse"
uuid = "9c0b9be8-e31e-490f-90fe-77697562404d"
authors = ["gaelforget <[email protected]> and contributors"]
version = "0.2.0"
version = "0.2.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
12 changes: 6 additions & 6 deletions src/downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ using Downloads, DataFrames
```
DOI="doi:10.7910/DVN/OYBLGK"
filename="polygons_MBON_seascapes.geojson"
file_download(DOI,filename)
Dataverse.file_download(DOI,filename)
```
"""
function file_download(DOI::String,nam::String,pth=tempdir())
df=file_list(DOI)
lst=url_list(df)
ownload_file_list(lst,filename,pth)
file_download(lst,nam,pth)
end

"""
file_download(lst::NamedTuple,nam::String,pth::String)
```
lst0=file_list("doi:10.7910/DVN/RNXA2A")
lst=downloads.url_list(lst0)
file_download(lst,lst.name[2],tempdir())
lst0=Dataverse.file_list("doi:10.7910/DVN/RNXA2A")
lst=Dataverse.url_list(lst0)
Dataverse.file_download(lst,lst.name[2],tempdir())
```
"""
function file_download(lists::NamedTuple,nam::String,pth=tempdir())
Expand All @@ -47,7 +47,7 @@ end
"""
url_list(lst::DataFrame)
Add download URL (using df.id) and return as NamedTuple.
Add download URL (using df.id) and return as `NamedTuple`.
"""
url_list(df::DataFrame) = begin
tmp="https://dataverse.harvard.edu/api/access/datafile/"
Expand Down
13 changes: 9 additions & 4 deletions src/restDataverse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ using HTTP, JSON, DataFrames
"""
file_list(DOI::String="doi:10.7910/DVN/ODM2IQ")
Use HTTP, JSON, DataFrames to list files (filename, filesize, id, pidURL).
Use HTTP, JSON, and DataFrames to list files in a dataset.
Return a DataFrame with filename, filesize, and id.
```
file_list("doi:10.7910/DVN/ODM2IQ")
Expand All @@ -29,14 +31,17 @@ function file_list(nam::Symbol)
file_list(DOI[nam])
end

#Convert output from `dataset.json()["data"]["latestVersion"]["files"]` to DataFrame
"""
files_to_DataFrame(files)
Convert output from `dataset.json()["data"]["latestVersion"]["files"]` to a `DataFrame`.
"""
function files_to_DataFrame(files)
nf=length(files)
filename=[files[ff]["dataFile"]["filename"] for ff in 1:nf]
filesize=[files[ff]["dataFile"]["filesize"] for ff in 1:nf]
id=[files[ff]["dataFile"]["id"] for ff in 1:nf]
pidURL=[files[ff]["dataFile"]["pidURL"] for ff in 1:nf]
DataFrame(filename=filename,filesize=filesize,id=id,pidURL=pidURL)
DataFrame(filename=filename,filesize=filesize,id=id)
end

end
Expand Down

0 comments on commit 86c4482

Please sign in to comment.