-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoi_resolver.py
More file actions
49 lines (37 loc) · 1.27 KB
/
doi_resolver.py
File metadata and controls
49 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
from habanero import counts
from habanero import Crossref
# import scholar.scholar as sch
#
# querier = sch.ScholarQuerier()
# settings = sch.ScholarSettings()
# settings.set_citation_format(4) #4 is for BibTex
# querier.apply_settings(settings)
def doi2bib(doi):
""" Return a bibTeX string of metadata for a given DOI."""
url = "http://dx.doi.org/" + doi
headers = {"accept": "application/x-bibtex"}
r = requests.get(url, headers = headers)
return r.text
def doi2count(doi):
return counts.citation_count(doi=doi)
def title2doi(title):
title = title.lower()
clean_title = ''.join(e for e in title if e.isalnum())
cr = Crossref()
res = cr.works(query_title=title, select="title,DOI", limit=5)
for r in res['message']['items']:
fetched_title = r['title'][0].lower()
clean_fetched = ''.join(e for e in fetched_title if e.isalnum())
if clean_fetched == clean_title:
return r['DOI']
# def title2bib(title):
# query = sch.SearchScholarQuery()
# query.set_words(title)
# query.set_num_page_results(1)
# querier.send_query(query)
# if len(querier.articles) > 0:
# bib = querier.articles[0].citation_data
# return bib.decode('utf-8')
# else:
# return ""