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
cff32d87
Commit
cff32d87
authored
3 years ago
by
JOUNEAU Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
d13de066
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
generate_citation.py
+116
-0
116 additions, 0 deletions
generate_citation.py
with
116 additions
and
0 deletions
generate_citation.py
0 → 100644
+
116
−
0
View file @
cff32d87
# ===================================================================================
# Génération de citations formatées sur la base d'un export JSON Dataverse
# ===================================================================================
print
(
"
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
"
)
print
(
"
# ===========================================================================#
"
)
print
(
"
# Génération de citations formatées sur la base #
"
)
print
(
"
# d
'
un export JSON Dataverse #
"
)
print
(
"
# ===========================================================================#
"
)
print
(
"
\n
"
)
# -----------------------
# Imports et déclarations
# -----------------------
import
json
import
os
from
pyDataverse.api
import
NativeApi
,
DataAccessApi
from
pyDataverse.models
import
Dataverse
# Fonction de génération de la citation
def
citation_generation
(
cit_authors
,
cit_title
,
cit_year
,
cit_data_repository
,
cit_version_number
,
cit_version_minor_number
,
cit_doi
,
cit_unf
):
cit_authors_len
=
len
(
cit_authors
)
cit_authors_len_test
=
cit_authors_len
for
cit_author
in
cit_authors
:
if
cit_authors_len_test
==
cit_authors_len
:
print
(
f
"
{
cit_author
}
;
"
,
end
=
''
)
else
:
print
(
f
"
{
cit_author
}
,
"
,
end
=
''
)
cit_authors_len_test
=
cit_authors_len_test
-
1
print
(
f
"
{
cit_year
}
,
"
,
end
=
''
)
print
(
f
"
\"
{
cit_title
}
\"
,
"
,
end
=
''
)
print
(
f
"
{
cit_data_repository
}
,
"
,
end
=
''
)
print
(
f
"
V
{
cit_version_number
}
.
{
cit_version_minor_number
}
,
"
,
end
=
''
)
print
(
f
"
http://dx.doi.org/
{
cit_doi
}
"
,
end
=
''
)
if
cit_unf
!=
""
:
print
(
f
"
UNF:
{
cit_unf
}
.
"
)
else
:
print
(
"
.
\n
"
)
# Fichier d'entrée
filename_input
=
input
(
"
Entrez le nom du fichier à traiter [export_json.json] :
"
)
if
filename_input
==
""
:
filename
=
"
export_json.json
"
else
:
filename
=
filename_input
with
open
(
filename
)
as
f
:
complete_list
=
json
.
load
(
f
)
for
doi
,
metadata
in
complete_list
.
items
():
#
# print (f"\n{doi} : \n")
authors_list
=
[]
subjects_list
=
[]
metadata
=
metadata
[
0
]
# le dictionnaire étant enserré entre des crochets, on prend le premier et unique élément de cette "liste"
# on récupère tout ce qu'on peut au niveau 1 de l'entrée et dans "latestVersion"
dataset_id
=
metadata
[
"
id
"
]
dataset_identifier
=
metadata
[
"
identifier
"
]
dataset_persistentUrl
=
metadata
[
"
persistentUrl
"
]
dataset_publicationDate
=
metadata
[
"
publicationDate
"
]
dataset_licence
=
metadata
[
"
latestVersion
"
][
"
license
"
]
dataset_publisher
=
metadata
[
"
publisher
"
]
dataset_publicationDate
:
metadata
[
"
publicationDate
"
]
dataset_yearofPublication
=
dataset_publicationDate
[
0
:
4
]
dataset_versionNumber
=
metadata
[
"
latestVersion
"
][
"
versionNumber
"
]
dataset_versionMinorNumber
=
metadata
[
"
latestVersion
"
][
"
versionMinorNumber
"
]
if
"
unf
"
in
metadata
[
"
latestVersion
"
]:
dataset_unf
=
metadata
[
"
latestVersion
"
][
"
UNF
"
]
else
:
dataset_unf
=
""
fields
=
metadata
[
"
latestVersion
"
][
"
metadataBlocks
"
][
"
citation
"
][
"
fields
"
]
for
field
in
fields
:
# chaque champ est pris l'un après l'autre. field est un dictionnaire
# print (field)
# print (f"{field['typeName']} : {field['value']}")
typeName
=
field
[
'
typeName
'
]
# title = "" # on définit par avance l'ensemble des champs en leur attribuant une valeur vide
# authors = ""
# datasetContacts = ""
# dsDescriptions = ""
# subjects = ""
# keywords = ""
# languages = ""
# depositors = ""
# dateOfDeposit = ""
if
typeName
==
'
title
'
:
title
=
field
[
'
value
'
]
# champ unique
if
typeName
==
'
author
'
:
authors
=
field
[
'
value
'
]
# liste de dictionnaires donc chaque élément est un auteur
for
author
in
authors
:
authorName
=
author
[
"
authorName
"
][
"
value
"
]
authors_list
.
append
(
authorName
)
if
typeName
==
'
datasetContact
'
:
datasetContacts
=
field
[
'
value
'
]
# champ multiple
if
typeName
==
'
dsDescription
'
:
dsDescriptions
=
field
[
'
value
'
]
# champ multiple
if
typeName
==
'
subject
'
:
subjects
=
field
[
'
value
'
]
# champ multiple
if
typeName
==
'
language
'
:
languages
=
field
[
'
value
'
]
# liste
if
typeName
==
'
depositor
'
:
depositors
=
field
[
'
value
'
]
if
typeName
==
'
keyword
'
:
keywords
=
field
[
'
value
'
]
if
typeName
==
'
dateofDeposit
'
:
dateofDeposit
=
field
[
'
value
'
]
citation_generation
(
cit_authors
=
authors_list
,
cit_title
=
title
,
cit_year
=
dataset_yearofPublication
,
cit_data_repository
=
dataset_publisher
,
cit_version_number
=
dataset_versionNumber
,
cit_version_minor_number
=
dataset_versionMinorNumber
,
cit_doi
=
doi
,
cit_unf
=
dataset_unf
)
\ 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