Skip to content
Snippets Groups Projects
Commit 7c03fc71 authored by Elias Chetouane's avatar Elias Chetouane
Browse files

Nouvelle version de la fonction

parent a2e04e76
No related branches found
No related tags found
No related merge requests found
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 ) :
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment