Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scripts pyDataverse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JOUNEAU Thomas
scripts pyDataverse
Commits
6f7816ab
Commit
6f7816ab
authored
3 years ago
by
JOUNEAU Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
01719df1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc/download_dataset.py
+56
-0
56 additions, 0 deletions
misc/download_dataset.py
with
56 additions
and
0 deletions
misc/download_dataset.py
0 → 100644
+
56
−
0
View file @
6f7816ab
#télécharger un jeu de données
# Importation de l'api native
from
pyDataverse.api
import
NativeApi
,
DataAccessApi
from
pyDataverse.models
import
Dataverse
# Déclaration de l'entrepôt Dataverse
repository_choice
=
False
while
repository_choice
==
False
:
if
repository_choice
==
True
:
break
prompt_repository_choice
=
"
Choix de l
'
entrepôt à requêter :
"
prompt_repository_choice
+=
"
\n\t
1. Entrepôt CODR (https://tested-dataverse5.univ-lorraine.fr
"
prompt_repository_choice
+=
"
\n\t
2. Entrepôt bac à sable (https://bac-dataverse.univ-lorraine.fr
"
prompt_repository_choice
+=
"
\n\t
3. Entrepôt DOREL / production (https://dorel.univ-lorraine.fr
"
prompt_repository_choice
+=
"
Entrez votre choix [1-3] :
"
choice_repository
=
input
(
prompt_repository_choice
)
if
choice_repository
==
"
1
"
and
repository_choice
==
False
:
base_url
=
"
https://tested-dataverse5.univ-lorraine.fr
"
repository_choice
=
True
elif
choice_repository
==
"
2
"
and
repository_choice
==
False
:
base_url
=
"
https://bac-dataverse.univ-lorraine.fr
"
repository_choice
=
True
elif
choice_repository
==
"
3
"
and
repository_choice
==
False
:
base_url
=
"
https://dorel.univ-lorraine.fr
"
repository_choice
=
True
else
:
print
(
"
\n
Je n
'
ai pas compris votre choix...
\n
"
)
api_key
=
input
(
"
Entrez ici votre clé API :
"
)
api
=
NativeApi
(
base_url
,
api_key
)
data_api
=
DataAccessApi
(
base_url
,
api_key
)
# Test de renvoi de version et de code http
print
(
"
Test de renvoi de version et de code http...
"
)
resp
=
api
.
get_info_version
()
print
(
resp
.
json
())
print
(
resp
.
status_code
)
print
(
resp
)
# Entrée du DOI
DOI_input
=
input
(
"
Entrer ici le DOI complet :
"
)
DOI
=
f
"
doi:
{
DOI_input
}
"
dataset
=
api
.
get_dataset
(
DOI
)
files_list
=
dataset
.
json
()[
'
data
'
][
'
latestVersion
'
][
'
files
'
]
for
file
in
files_list
:
filename
=
file
[
"
dataFile
"
][
"
filename
"
]
file_id
=
file
[
"
dataFile
"
][
"
id
"
]
print
(
"
File name {}, id {}
"
.
format
(
filename
,
file_id
))
response
=
data_api
.
get_datafile
(
file_id
)
with
open
(
filename
,
"
wb
"
)
as
f
:
f
.
write
(
response
.
content
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment