Commit 256942c5 authored by Bruno Chareyre's avatar Bruno Chareyre
Browse files

build orcid output

parent 46ef02c6
Pipeline #68692 passed with stages
in 2 minutes and 54 seconds
......@@ -7,6 +7,77 @@ N_PUBLI_MAX = 100
N_PUBLIS = [3, 5, 10, 15, 50, 100]
MAX_AUTHORS = 3
groups = { 'geo' : { 'Chareyre': '0000-0001-8505-8540',
'Viggiani': '0000-0002-2609-6077',
'DiDona' : '0000-0002-4383-852X',
'Emeriault': '0000-0001-8160-1075',
'Sibille': '0000-0002-3510-3400',
'Villard': '0000-0002-3327-6463',
'Combe': '0000-0002-8633-0793',
'Tengattini': '0000-0003-0320-3340',
'Besuelle': '0000-0001-9586-4888',
'Richefeu': '0000-0002-8897-5499',
'Jenck': '0000-0002-2623-1830',
'Loret': '0000-0002-2622-3179',
'Dano': '0000-0001-8648-7195',
'Daudon': '0000-0003-0233-5608',
}}
test=None
def html_publi_orcid(publi):
global test
cite = []
test=publi
# get names
print(len(publi))
print(publi)
authors = [n['credit-name']['value'] for n in publi['contributors']['contributor']]
if len(authors) > MAX_AUTHORS:
authors_displayed = authors[:MAX_AUTHORS]
authors_displayed.append(f'<span class="author"><i>et. al.</i></span>')
else:
authors_displayed = authors
print(authors_displayed)
cite.append(f'<span class="authors" title="">{", ".join(authors_displayed)}</span>')
# get title and url
try:
url = publi["url"]["value"]
except:
print('url not found')
url = ''
cite.append(f'<span class="article"><a href="{url}" target="_blank">{publi["title"]["title"]["value"]}</a></span>')
# get journal
try:
journal = publi['journal-title']['value']
except:
print('journal not found')
journal=''
print(journal)
if len(journal):
cite.append(f'<span class="journal">{journal}</span>')
# get year
cite.append(f'<span class="year">{publi["publication-date"]["year"]["value"]}</span>')
# get month
try:
month = publi["publication-date"]["month"]["value"]
except:
month = ""
# get doi
try:
doi = publi['external-ids']['external-id'][0]['external-id-value']
except:
doi=''
if len(doi):
cite.append(f'<span class="doi"><a href="https://doi.org/{doi}" >{doi}</a></span>')
return ' '.join(cite)
def html_publi(publi):
cite = []
......@@ -88,6 +159,147 @@ def get_biblio_structure(structure_name, structure_id, n_publi=100):
return files
def get_biblio_orcid(name='Chareyre',orcid='0000-0001-8505-8540',N=10):
BRIDGE_TYPES = {"ART": "journal-article", "COMM": "Conferences", "COUV": "Books", "THESE": "These"}
req = "https://pub.orcid.org/v3.0/"+orcid+"/works"
#req = "http://api.archives-ouvertes.fr/search/?q=(authIdHal_s:{s})&sort={so} desc&rows={n}&fl=*".format(s=idhal, n=N_PUBLI_MAX, so=SORT_BY)
publis_by_type = dict()
api_error = dict()
publis = requests.get(req, headers={'Accept': 'application/json',}).json()
publis = publis["group"]
#req_author = 'https://api.archives-ouvertes.fr/ref/author/?q=idHal_s:{s}'.format(s=idhal)
#idhal_info = requests.get(req_author).json()
req_author = 'req_author'
idhal_info = 'idhal_info'
for i, publi in enumerate(publis):
work=publi.get("work-summary")[0]
doc = requests.get('http://pub.orcid.org/'+work['path'],
headers={'Accept':'application/orcid+json'}).json()
type = BRIDGE_TYPES.get(work.get("type")) if BRIDGE_TYPES.get(work.get("type")) is not None else work.get("type")
print("type",type)
if type in publis_by_type:
publis_by_type[type].append(doc)
else:
publis_by_type[type] = [doc]
if i>=N: break
#try:
#print(doc['citation']['citation-value'])
#except:
#print('http://pub.orcid.org/'+work['path'], "FAILED\n",'http://pub.orcid.org/'+doc['title']['title']['value'])
file = "{}_orcid.html".format(name)
print(file)
with open(file, 'w') as f:
f.write('<!DOCTYPE html>\n')
f.write('<html>\n')
f.write('\t<head>\n')
f.write('\t\t<meta charset="UTF-8">\n')
f.write('\t\t<link rel="stylesheet" href="biblio.css">\n')
f.write('\t</head>\n')
f.write('\t<body class="perso">\n')
for type, publis in publis_by_type.items():
f.write('\t\t<h4>{}</h4>\n'.format(type))
f.write('\t\t<ul>\n')
for publi in publis:
f.write('\t\t\t<li>{}</li>\n'.format(html_publi_orcid(publi)))
f.write('\t\t</ul>\n')
f.write('\t</body>\n')
f.write('</html>')
return [file]
def get_biblio_group_orcid(groupName='geo',N=20,typesLists = [['journal-article'],['all']]):
global test
BRIDGE_TYPES = {"ART": "journal-article", "COMM": "Conferences", "COUV": "Books", "THESE": "These"}
publis_by_type = dict()
group = groups[groupName]
for author in group:
name = author
orcid = group[name]
req = "https://pub.orcid.org/v3.0/"+orcid+"/works"
#req = "http://api.archives-ouvertes.fr/search/?q=(authIdHal_s:{s})&sort={so} desc&rows={n}&fl=*".format(s=idhal, n=N_PUBLI_MAX, so=SORT_BY)
api_error = dict()
publis = requests.get(req, headers={'Accept': 'application/json',}).json()
publis = publis["group"]
#req_author = 'https://api.archives-ouvertes.fr/ref/author/?q=idHal_s:{s}'.format(s=idhal)
#idhal_info = requests.get(req_author).json()
req_author = 'req_author'
idhal_info = 'idhal_info'
for i, publi in enumerate(publis):
work=publi.get("work-summary")[0]
type = BRIDGE_TYPES.get(work.get("type")) if BRIDGE_TYPES.get(work.get("type")) is not None else work.get("type")
print(author," : type",type)
doc = requests.get('http://pub.orcid.org/'+work['path'],
headers={'Accept':'application/orcid+json'}).json()
year = doc["publication-date"]["year"]["value"]
try:
key = doc['external-ids']['external-id'][0]['external-id-value']
except:
print("key not found")
key =''
try:
month = publi["publication-date"]["month"]["value"]
except:
month = '00'
doc['time']=year+month
if type in publis_by_type:
publis_by_type[type][key] = doc
else:
publis_by_type[type] = dict()
publis_by_type[type][key] = doc
if i>=8: break
#try:
#print(doc['citation']['citation-value'])
#except:
#print('http://pub.orcid.org/'+work['path'], "FAILED\n",'http://pub.orcid.org/'+doc['title']['title']['value'])
print("NAME: ",groupName)
files=[]
for listT in typesLists:
if listT[0]=='all': types = [i for i in publis_by_type.keys()]
else: types = listT
file = "{}_{}_{}_orcid.html".format(groupName,listT[0],str(N))
print(file)
with open(file, 'w') as f:
f.write('<!DOCTYPE html>\n')
f.write('<html>\n')
f.write('\t<head>\n')
f.write('\t\t<meta charset="UTF-8">\n')
f.write('\t\t<link rel="stylesheet" href="biblio.css">\n')
f.write('\t</head>\n')
f.write('\t<body class="perso">\n')
for type in types:
publis = publis_by_type[type]
#for type, publis in publis_by_type.items():
print("Type",type,publis)
#>>> x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
#>>> {k: v for k, v in sorted(x.items(), key=lambda item: item[1])}
#{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}
# sort by time
test = publis.items()
publis = {k: v for k,v in sorted(publis.items(), key=lambda item: item[1]['time'], reverse=True) }
f.write('\t\t<h4>{}</h4>\n'.format(type))
f.write('\t\t<ul>\n')
for key, publi in publis.items():
print(publi)
f.write('\t\t\t<li>{}</li>\n'.format(html_publi_orcid(publi)))
f.write('\t\t</ul>\n')
f.write('\t</body>\n')
f.write('</html>')
files.append(file)
return files
def get_biblio_idhal(idhal):
req = "http://api.archives-ouvertes.fr/search/?q=(authIdHal_s:{s})&sort={so} desc&rows={n}&fl=*".format(s=idhal, n=N_PUBLI_MAX, so=SORT_BY)
publis_by_type = dict()
......@@ -125,6 +337,10 @@ def get_biblio_idhal(idhal):
return [file]
all_files = []
for group in groups:
all_files.append(get_biblio_group_orcid(group))
for author in groups[group]:
all_files.append(get_biblio_orcid(author,groups[group][author]))
all_files.append(get_biblio_structure("geo", 1041793))
all_files.append(get_biblio_structure("comhet", 545341))
all_files.append(get_biblio_structure("rv", 545342))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment