parent
44b0c5b4c9
commit
7776b65de2
@ -54,7 +54,7 @@ def command(conf, args):
|
|||||||
papers = sorted(papers, key=date_added)
|
papers = sorted(papers, key=date_added)
|
||||||
if len(papers) > 0:
|
if len(papers) > 0:
|
||||||
ui.message('\n'.join(
|
ui.message('\n'.join(
|
||||||
pretty.paper_oneliner(p, citekey_only=args.citekeys)
|
pretty.paper_oneliner(p, citekey_only=args.citekeys, n_authors=conf['main']['n_authors'])
|
||||||
for p in papers))
|
for p in papers))
|
||||||
|
|
||||||
rp.close()
|
rp.close()
|
||||||
|
@ -27,6 +27,9 @@ edit_cmd = string(default='')
|
|||||||
# Which default extension to use when creating a note file.
|
# Which default extension to use when creating a note file.
|
||||||
note_extension = string(default='txt')
|
note_extension = string(default='txt')
|
||||||
|
|
||||||
|
# How many authors to display in
|
||||||
|
n_authors = integer(default=3)
|
||||||
|
|
||||||
# If true debug mode is on which means exceptions are not catched and
|
# If true debug mode is on which means exceptions are not catched and
|
||||||
# the full python stack is printed.
|
# the full python stack is printed.
|
||||||
debug = boolean(default=False)
|
debug = boolean(default=False)
|
||||||
|
@ -23,19 +23,30 @@ def person_repr(p):
|
|||||||
' '.join(p.lineage(abbr=True))] if s)
|
' '.join(p.lineage(abbr=True))] if s)
|
||||||
|
|
||||||
|
|
||||||
def short_authors(bibdata):
|
def short_authors(bibdata, n_authors=3):
|
||||||
|
"""
|
||||||
|
:param n_authors: number of authors to display completely. Additional authors will be
|
||||||
|
represented by 'et al.'.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
authors = [p for p in bibdata['author']]
|
authors = [p for p in bibdata['author']]
|
||||||
if len(authors) < 3:
|
if 0 < n_authors < len(authors):
|
||||||
return ' and '.join(authors)
|
authors_str = '{} et al.'.format(authors[0])
|
||||||
else:
|
else:
|
||||||
return authors[0] + (' et al.' if len(authors) > 1 else '')
|
authors_str = ' and '.join(authors)
|
||||||
|
|
||||||
|
# if n_authors > 0:
|
||||||
|
# authors = authors[:n_authors]
|
||||||
|
# authors_str = ' and '.join(authors)
|
||||||
|
# if 0 < n_authors < len(bibdata['author']):
|
||||||
|
# authors_str += ' et al.'
|
||||||
|
return authors_str
|
||||||
except KeyError: # When no author is defined
|
except KeyError: # When no author is defined
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def bib_oneliner(bibdata):
|
def bib_oneliner(bibdata, n_authors=3):
|
||||||
authors = short_authors(bibdata)
|
authors = short_authors(bibdata, n_authors=n_authors)
|
||||||
journal = ''
|
journal = ''
|
||||||
if 'journal' in bibdata:
|
if 'journal' in bibdata:
|
||||||
journal = ' ' + bibdata['journal']
|
journal = ' ' + bibdata['journal']
|
||||||
@ -60,11 +71,11 @@ def bib_desc(bib_data):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def paper_oneliner(p, citekey_only=False):
|
def paper_oneliner(p, citekey_only=False, n_authors=3):
|
||||||
if citekey_only:
|
if citekey_only:
|
||||||
return p.citekey
|
return p.citekey
|
||||||
else:
|
else:
|
||||||
bibdesc = bib_oneliner(p.get_unicode_bibdata())
|
bibdesc = bib_oneliner(p.get_unicode_bibdata(), n_authors=n_authors)
|
||||||
doc_str = ''
|
doc_str = ''
|
||||||
if p.docpath is not None:
|
if p.docpath is not None:
|
||||||
doc_extension = os.path.splitext(p.docpath)[1]
|
doc_extension = os.path.splitext(p.docpath)[1]
|
||||||
|
@ -28,5 +28,15 @@ class TestPretty(unittest.TestCase):
|
|||||||
line = 'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web."'
|
line = 'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web."'
|
||||||
self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'])), line)
|
self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'])), line)
|
||||||
|
|
||||||
|
def test_oneliner_n_authors(self):
|
||||||
|
decoder = endecoder.EnDecoder()
|
||||||
|
bibdata = decoder.decode_bibdata(bibtex_raw0)
|
||||||
|
for n_authors in [1, 2, 3]:
|
||||||
|
line = 'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999)'
|
||||||
|
self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'], n_authors=n_authors)), line)
|
||||||
|
for n_authors in [-1, 0, 4, 5, 10]:
|
||||||
|
line = 'Page, Lawrence and Brin, Sergey and Motwani, Rajeev and Winograd, Terry "The PageRank Citation Ranking: Bringing Order to the Web." (1999)'
|
||||||
|
self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'], n_authors=n_authors)), line)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -1079,7 +1079,8 @@ class TestUsecase(DataCommandTestCase):
|
|||||||
'pubs add -d data/no-ext data/pagerank.bib',
|
'pubs add -d data/no-ext data/pagerank.bib',
|
||||||
'pubs list',
|
'pubs list',
|
||||||
]
|
]
|
||||||
self.assertEqual(correct, self.execute_cmds(cmds, capture_output=True))
|
actual = self.execute_cmds(cmds, capture_output=True)
|
||||||
|
self.assertEqual(correct, actual)
|
||||||
|
|
||||||
@mock.patch('pubs.apis.requests.get', side_effect=mock_requests.mock_requests_get)
|
@mock.patch('pubs.apis.requests.get', side_effect=mock_requests.mock_requests_get)
|
||||||
def test_readme(self, reqget):
|
def test_readme(self, reqget):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user