From 7c03fc7140ad2bf0d66d58dad6c3022e632826e8 Mon Sep 17 00:00:00 2001 From: Elias Chetouane <elias.chetouane@univ-grenoble-alpes.fr> Date: Mon, 25 Mar 2024 15:45:11 +0100 Subject: [PATCH] Nouvelle version de la fonction --- .../z_personal_functions.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/1-enrich-with-datacite/z_personal_functions.py b/1-enrich-with-datacite/z_personal_functions.py index 84aa0e7..053c1a0 100644 --- a/1-enrich-with-datacite/z_personal_functions.py +++ b/1-enrich-with-datacite/z_personal_functions.py @@ -1,19 +1,30 @@ import requests, json -def get_origin_version(doi, count=1): +def get_origin_version(doi, count=0, cited=0): + cited = 0 req = requests.get( f"https://api.datacite.org/dois/{doi}" ) res = req.json() + result = (doi, count, cited) try: - origins = res["data"]["attributes"]["relatedIdentifiers"] + related = res["data"]["attributes"]["relatedIdentifiers"] except: - return doi, count + pass else: - if origins == []: return doi, count - for i in origins: - if i["relationType"] != "IsVersionOf": - return doi, count - else: - return get_origin_version(i["relatedIdentifier"], count+1) + ignore = False + duplicate = False + for i in related: + if i["relationType"] == "IsVersionOf" and i.get("relatedIdentifierType") == "DOI": + ignore = True + elem_to_save_i = i["relatedIdentifier"] + # supprimer le doi courant s'il apparait dans la liste + if i["relationType"] == "isCitedBy" and i.get("relatedIdentifierType") == "DOI": cited += 1 + if i["relationType"] == "IsIdenticalTo" and i.get("relatedIdentifierType") == "DOI": + duplicate = True + elem_to_save_d = i["relatedIdentifier"] + if duplicate and not(ignore): + result = (elem_to_save_d, count, cited) + if ignore: result = get_origin_version(elem_to_save_i, count+1, cited) + return result def get_md_from_datacite( doi ) : """ -- GitLab