Add a command to open urls
This commit is contained in:
parent
29aed39bf8
commit
bff1f5763d
@ -15,5 +15,6 @@ from . import export_cmd
|
|||||||
from . import import_cmd
|
from . import import_cmd
|
||||||
# bonus
|
# bonus
|
||||||
from . import websearch_cmd
|
from . import websearch_cmd
|
||||||
|
from . import url_cmd
|
||||||
|
|
||||||
from . import edit_cmd
|
from . import edit_cmd
|
||||||
|
35
pubs/commands/url_cmd.py
Normal file
35
pubs/commands/url_cmd.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
from .. import p3
|
||||||
|
from .. import repo
|
||||||
|
from ..uis import get_ui
|
||||||
|
from ..utils import resolve_citekey, resolve_citekey_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def parser(subparsers, conf):
|
||||||
|
parser = subparsers.add_parser('url',
|
||||||
|
help="open the url in the browser")
|
||||||
|
parser.add_argument("citekey", nargs = '*',
|
||||||
|
help="one or more citeKeys to open")
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def command(conf, args):
|
||||||
|
"""Open the url for a publication."""
|
||||||
|
|
||||||
|
ui = get_ui()
|
||||||
|
rp = repo.Repository(conf)
|
||||||
|
|
||||||
|
for key in resolve_citekey_list(rp, args.citekey, ui=ui, exit_on_fail=True):
|
||||||
|
try:
|
||||||
|
paper = rp.pull_paper(key)
|
||||||
|
url = paper.bibdata['url']
|
||||||
|
webbrowser.open(url)
|
||||||
|
|
||||||
|
except KeyError as e:
|
||||||
|
ui.error(key, 'has no url')
|
||||||
|
|
||||||
|
rp.close()
|
@ -29,6 +29,7 @@ CORE_CMDS = collections.OrderedDict([
|
|||||||
('import', commands.import_cmd),
|
('import', commands.import_cmd),
|
||||||
|
|
||||||
('websearch', commands.websearch_cmd),
|
('websearch', commands.websearch_cmd),
|
||||||
|
('url', commands.url_cmd),
|
||||||
('edit', commands.edit_cmd),
|
('edit', commands.edit_cmd),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user