Fix an error when no publications was returned in doi.get_oa_policy()

This commit is contained in:
Lucas Verney 2016-02-11 15:32:05 +01:00
parent 0e85a039d8
commit aff46b273d
2 changed files with 6 additions and 2 deletions

View File

@ -7,7 +7,7 @@ __valid_identifiers__ = []
from . import bibtex, doi, fetcher, isbn # noqa from . import bibtex, doi, fetcher, isbn # noqa
from . import citations, papers, repositories # noqa from . import citations, papers, repositories # noqa
__version__ = "0.1.2" __version__ = "0.1.3.1"
__all__ = [ __all__ = [
"bibtex", "doi", "fetcher", "isbn", "bibtex", "doi", "fetcher", "isbn",

View File

@ -157,6 +157,9 @@ def get_oa_policy(doi):
>>> tmp = get_oa_policy('10.1209/0295-5075/111/40005'); (tmp["published"], tmp["preprint"], tmp["postprint"], tmp["romeo_id"]) >>> tmp = get_oa_policy('10.1209/0295-5075/111/40005'); (tmp["published"], tmp["preprint"], tmp["postprint"], tmp["romeo_id"])
('can', 'can', 'can', '1896') ('can', 'can', 'can', '1896')
>>> get_oa_policy('10.1215/9780822387268') is None
True
""" """
try: try:
r = requests.get("%s%s" % (DISSEMIN_API, doi)) r = requests.get("%s%s" % (DISSEMIN_API, doi))
@ -166,7 +169,8 @@ def get_oa_policy(doi):
return ([i return ([i
for i in result["paper"]["publications"] for i in result["paper"]["publications"]
if i["doi"] == doi][0])["policy"] if i["doi"] == doi][0])["policy"]
except (AssertionError, ValueError, KeyError, RequestException): except (AssertionError, ValueError,
KeyError, RequestException, IndexError):
return None return None