diff --git a/arxiv.py b/arxiv.py index f9dc958..ab5b563 100644 --- a/arxiv.py +++ b/arxiv.py @@ -1,3 +1,6 @@ +""" +This file contains all the arXiv-specific functions. +""" import bbl import io import requests diff --git a/bbl.py b/bbl.py index 97ace12..63d6e95 100644 --- a/bbl.py +++ b/bbl.py @@ -1,3 +1,6 @@ +""" +This files contains all the functions to deal with bbl files. +""" import doi import math import os diff --git a/doi.py b/doi.py index 76c69a6..46a66ba 100644 --- a/doi.py +++ b/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 diff --git a/main.py b/main.py index f2fd229..dc5721d 100755 --- a/main.py +++ b/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: diff --git a/regex.py b/regex.py index 940f2de..584d8ef 100644 --- a/regex.py +++ b/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]))+") diff --git a/tools.py b/tools.py index c793256..e0728fd 100644 --- a/tools.py +++ b/tools.py @@ -1,3 +1,8 @@ +""" +This file contains various utility functions. +""" + + def replaceAll(text, dic): """Replace all the dic keys by the associated item in text""" for i, j in dic.items():