Add a function to look for an OA version for a given DOI

This commit is contained in:
Lucas Verney 2015-12-23 23:03:40 +01:00
parent fecf3e02b9
commit 97fef88498
6 changed files with 43 additions and 8 deletions

View File

@ -1,3 +1,6 @@
"""
This file contains all the arXiv-specific functions.
"""
import bbl import bbl
import io import io
import requests import requests

3
bbl.py
View File

@ -1,3 +1,6 @@
"""
This files contains all the functions to deal with bbl files.
"""
import doi import doi
import math import math
import os import os

29
doi.py
View File

@ -1,3 +1,8 @@
"""
This file contains all the DOI-related functions.
"""
import requests
import regex import regex
import tools import tools
@ -75,3 +80,27 @@ def match_doi_or_arxiv(text, only=["DOI", "arXiv"]):
if extractID: if extractID:
return ("arXiv", extractID.group(1)) return ("arXiv", extractID.group(1))
return None 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

View File

@ -7,14 +7,6 @@ import arxiv
import bbl 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__": if __name__ == "__main__":
import pprint import pprint
if len(sys.argv) < 2: if len(sys.argv) < 2:

View File

@ -1,3 +1,6 @@
"""
This file contains all the regex used across the app.
"""
import re import re
urls = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+") urls = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")

View File

@ -1,3 +1,8 @@
"""
This file contains various utility functions.
"""
def replaceAll(text, dic): def replaceAll(text, dic):
"""Replace all the dic keys by the associated item in text""" """Replace all the dic keys by the associated item in text"""
for i, j in dic.items(): for i, j in dic.items():