experimental support for adding from DOIs
This commit is contained in:
parent
2e5defeb52
commit
adb0158c3d
12
pubs/apis.py
Normal file
12
pubs/apis.py
Normal file
@ -0,0 +1,12 @@
|
||||
"""Interface for Remote Bibliographic APIs"""
|
||||
|
||||
import requests
|
||||
|
||||
def doi2bibtex(doi):
|
||||
"""Return a bibtex string of metadata from a DOI"""
|
||||
|
||||
url = 'http://dx.doi.org/{}'.format(doi)
|
||||
headers = {'accept': 'application/x-bibtex'}
|
||||
r = requests.get(url, headers=headers)
|
||||
|
||||
return r.text
|
@ -5,12 +5,14 @@ from .. import content
|
||||
from .. import repo
|
||||
from .. import paper
|
||||
from .. import templates
|
||||
from .. import apis
|
||||
|
||||
|
||||
def parser(subparsers):
|
||||
parser = subparsers.add_parser('add', help='add a paper to the repository')
|
||||
parser.add_argument('bibfile', nargs='?', default = None,
|
||||
help='bibtex, bibtexml or bibyaml file')
|
||||
help='bibtex file')
|
||||
parser.add_argument('-D', '--doi', help='doi number to retrieve the bibtex entry, if it is not provided', default=None)
|
||||
parser.add_argument('-d', '--docfile', help='pdf or ps file', default=None)
|
||||
parser.add_argument('-t', '--tags', help='tags associated to the paper, separated by commas',
|
||||
default=None)
|
||||
@ -65,10 +67,17 @@ def command(args):
|
||||
|
||||
rp = repo.Repository(config())
|
||||
|
||||
# get bibfile
|
||||
|
||||
# get bibtex entry
|
||||
if bibfile is None:
|
||||
bibdata = bibdata_from_editor(ui, rp)
|
||||
if args.doi is None:
|
||||
bibdata = bibdata_from_editor(ui, rp)
|
||||
else:
|
||||
bibdata_raw = apis.doi2bibtex(args.doi)
|
||||
bibdata = rp.databroker.verify(bibdata_raw)
|
||||
if bibdata is None:
|
||||
ui.error('invalid doi {} or unable to retreive bibfile.'.format(doi))
|
||||
# TODO distinguish between cases, offer to open the error page in a webbrowser.
|
||||
# TODO offer to confirm/change citekey
|
||||
else:
|
||||
bibdata_raw = content.get_content(bibfile, ui=ui)
|
||||
bibdata = rp.databroker.verify(bibdata_raw)
|
||||
|
3
setup.py
3
setup.py
@ -12,10 +12,11 @@ setup(
|
||||
url = '',
|
||||
|
||||
description = 'command-line scientific bibliography manager',
|
||||
requires = ['pyyaml', 'bibtexparser', 'dateutil'],
|
||||
packages = find_packages(),
|
||||
scripts = ['pubs/pubs'],
|
||||
|
||||
install_requires = ['pyyaml', 'bibtexparser', 'python-dateutil', 'requests'],
|
||||
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
|
||||
|
Loading…
x
Reference in New Issue
Block a user