Add a function to look for an OA version for a given DOI
This commit is contained in:
parent
fecf3e02b9
commit
97fef88498
3
arxiv.py
3
arxiv.py
@ -1,3 +1,6 @@
|
||||
"""
|
||||
This file contains all the arXiv-specific functions.
|
||||
"""
|
||||
import bbl
|
||||
import io
|
||||
import requests
|
||||
|
3
bbl.py
3
bbl.py
@ -1,3 +1,6 @@
|
||||
"""
|
||||
This files contains all the functions to deal with bbl files.
|
||||
"""
|
||||
import doi
|
||||
import math
|
||||
import os
|
||||
|
29
doi.py
29
doi.py
@ -1,3 +1,8 @@
|
||||
"""
|
||||
This file contains all the DOI-related functions.
|
||||
"""
|
||||
import requests
|
||||
|
||||
import regex
|
||||
import tools
|
||||
|
||||
@ -75,3 +80,27 @@ def match_doi_or_arxiv(text, only=["DOI", "arXiv"]):
|
||||
if extractID:
|
||||
return ("arXiv", extractID.group(1))
|
||||
return None
|
||||
|
||||
|
||||
def get_oa_version(doi):
|
||||
"""
|
||||
Get an OA version for a given DOI.
|
||||
|
||||
Params:
|
||||
- doi is a DOI or a dx.doi.org link.
|
||||
|
||||
Returns the URL of the OA version of the given DOI, or None.
|
||||
"""
|
||||
# If DOI is a link, truncate it
|
||||
if "dx.doi.org" in doi:
|
||||
doi = doi[doi.find("dx.doi.org") + 11:]
|
||||
r = requests.get("http://beta.dissem.in/api/%s" % (doi,))
|
||||
oa_url = None
|
||||
if r.status_code == requests.codes.ok:
|
||||
result = r.json()
|
||||
if("status" in result and
|
||||
"paper" in result and
|
||||
result["status"] == "ok" and
|
||||
"pdf_url" in result["paper"]):
|
||||
oa_url = result["paper"]["pdf_url"]
|
||||
return oa_url
|
||||
|
8
main.py
8
main.py
@ -7,14 +7,6 @@ import arxiv
|
||||
import bbl
|
||||
|
||||
|
||||
def oa_from_doi(doi):
|
||||
"""
|
||||
Get an OA version for a given DOI.
|
||||
"""
|
||||
# http://beta.dissem.in/api/10.1088/1367-2630/17/9/093036
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pprint
|
||||
if len(sys.argv) < 2:
|
||||
|
3
regex.py
3
regex.py
@ -1,3 +1,6 @@
|
||||
"""
|
||||
This file contains all the regex used across the app.
|
||||
"""
|
||||
import re
|
||||
|
||||
urls = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
|
||||
|
Loading…
Reference in New Issue
Block a user