diff options
author | Alejandro Gallo <aamsgallo@gmail.com> | 2018-06-11 08:18:30 +0200 |
---|---|---|
committer | Alejandro Gallo <aamsgallo@gmail.com> | 2018-06-11 08:18:30 +0200 |
commit | c53034e1b995073fac4d68df36994b44a0be7592 (patch) | |
tree | 0cbd5d1f300560f810f0d14444d7b540dd8b727e | |
parent | 10296db2eb2737f0695ed812708f4e0ec68a32e4 (diff) | |
parent | a10ce1ebac0c9231ff2e0b4fc33916739766fd84 (diff) |
Merge branch 'master' into serve
-rw-r--r-- | AUTHORS | 9 | ||||
-rwxr-xr-x | examples/scripts/papis-hubation | 45 | ||||
-rwxr-xr-x | examples/scripts/papis-zotero | 1 | ||||
-rw-r--r-- | papis/config.py | 48 | ||||
-rw-r--r-- | papis/crossref.py | 11 | ||||
-rw-r--r-- | papis/document.py | 69 |
6 files changed, 162 insertions, 21 deletions
@@ -1,8 +1,9 @@ -894 Alejandro Gallo <aamsgallo@gmail.com> -11 Nicolò Balzarotti <anothersms@gmail.com> +1037 Alejandro Gallo <aamsgallo@gmail.com> +38 Nicolò Balzarotti <anothersms@gmail.com> +12 michaelplews <michael.plews@gmail.com> 9 alejandrogallo <alejandrogallo@users.noreply.github.com> -8 michaelplews <michael.plews@gmail.com> -4 Michael R. Plews <michael.plews@gmail.com> +5 Michael R. Plews <michael.plews@gmail.com> +1 Dennis Bruggner <dennis@bruggner.net> 1 Felix Hummel <felix.hummel@tuwien.ac.at> 1 Katrin Leinweber <9948149+katrinleinweber@users.noreply.github.com> 1 Theo Tsatsoulis <T.Tsatsoulis@fkf.mpg.de> diff --git a/examples/scripts/papis-hubation b/examples/scripts/papis-hubation index 68b0484e..6d8dbb6d 100755 --- a/examples/scripts/papis-hubation +++ b/examples/scripts/papis-hubation @@ -43,15 +43,19 @@ if 'citations' not in doc.keys(): dois = [d.get('doi') for d in doc['citations']] print("%s citations found" % len(dois)) -print("Fetching citations' information online") +print("Fetching citations'") dois_with_data = [] for j,doi in enumerate(dois): progress = "%s/%s (doi: %s)" % (j+1, len(dois), doi) sys.stdout.write(progress) sys.stdout.flush() - dois_with_data.append( - papis.crossref.doi_to_data(doi) - ) + citation = papis.api.get_documents_in_lib(papis.api.get_lib(),search='doi = "%s"' % doi) + if citation: + dois_with_data.append(papis.api.pick_doc(citation)) + else: + dois_with_data.append( + papis.crossref.doi_to_data(doi) + ) sys.stdout.write("\b" * (len(progress))) sys.stdout.write(" " * (len(progress))) sys.stdout.flush() @@ -65,9 +69,32 @@ doi or sys.exit(0) print('DOI %s selected' % doi) -papis.commands.main( - [ - 'scihub', doi - ] + add_flags -) +# set citation as the doc if it's already in the library +citation = papis.api.get_documents_in_lib(papis.api.get_lib(),search='doi = "%s"' % doi) + +# get hubation options +config_options = papis.config.get('hubation') + +# if open in config_options... +if 'open' in config_options: + # Check if the citation is already in your library + if citation: + # and open the associated file + papis.commands.main( + [ + 'open', "ref=%s" % doc['ref'] + ] + ) + else: + # if it isn't, open in a browser + papis.document.open_in_browser(doc) +elif 'browse' in config_options: + papis.document.open_in_browser(doc) + +else: + papis.commands.main( + [ + papis.config.get('hubation'), "ref=%s" % doc['ref'] + ] + add_flags + ) diff --git a/examples/scripts/papis-zotero b/examples/scripts/papis-zotero index b5aef651..3a786450 100755 --- a/examples/scripts/papis-zotero +++ b/examples/scripts/papis-zotero @@ -42,6 +42,7 @@ def add(entry, pdf_file=None): fd.close() papis.commands.main( [ + '-l', papis.api.get_lib(), 'add', pdf_file or '--no-document', '--from-yaml', temp ] + add_flags ) diff --git a/papis/config.py b/papis/config.py index 8c24dd06..ab7c2236 100644 --- a/papis/config.py +++ b/papis/config.py @@ -168,6 +168,15 @@ Tools options Bibtex options ^^^^^^^^^^^^^^ +.. papis-config:: bibtex-journal-key + + Journal publishers may request abbreviated journal titles. This + option allows the user to set the key for the journal entry when using + ``papis export --bibtex``. + + Set as ``full_journal_title`` or ``abbrev_journal_title`` for + whichever style required. Default is ``journal``. + .. papis-config:: extra-bibtex-keys When exporting documents in bibtex format, you might want to add @@ -280,6 +289,22 @@ Add command options papis add doc.pdf --author 'Bohm' --title 'Super book' --year 1928 +Browse command options +^^^^^^^^^^^^^^^^^^^^^^ + +.. papis-config:: browse-key + + This command provides the key that is used to generate the + url. For users that ``papis add --from-doi``, setting browse-key + to ``doi`` constructs the url from dx.doi.org/DOI, providing a + much more accurate url. + + Default value is set to ``url``. If the user needs functionality + with the ``search-engine`` option, set the option to an empty + string e.g. :: + + browse-key = '' + .. _check-command-options: Check command options @@ -430,6 +455,25 @@ Databases `the documentation <https://whoosh.readthedocs.io/en/latest/schema.html/>`_ for more information. +Other +===== + +.. papis-config:: hubation + + This allows the operation after picking be set when using the + script papis-hubation. Running ``papis hubation`` provides a list + of citations, which once picked, can undergo the operation + 'e.g. open, browse, scihub' that is set. Current tested options are + ``open``, ``browse``, ``export``, and ``scihub``. + + Default behaviour is set to scihub. + +.. papis-config:: citation-string + + string that can be displayed in header if the reference has a + citation + + Default set to '*' """ import logging @@ -493,6 +537,7 @@ general_settings = { "add-default-fields": '["title", "author"]', "check-keys": '["files"]', + "browse-key": '"url"', "browse-query-format": "{doc[title]} {doc[author]}", "search-engine": "https://duckduckgo.com", "user-agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3)', @@ -509,6 +554,7 @@ general_settings = { "mark-opener-format": get_default_opener(), "file-browser": get_default_opener(), + "bibtex-journal-key": 'journal', "extra-bibtex-keys": "", "extra-bibtex-types": "", "default-library": "papers", @@ -537,6 +583,8 @@ general_settings = { '"tags": TEXT(stored=True),\n' '}', + "hubation": "scihub", + "citation-string": "*" } diff --git a/papis/crossref.py b/papis/crossref.py index cfa8a71c..b93f2018 100644 --- a/papis/crossref.py +++ b/papis/crossref.py @@ -150,6 +150,15 @@ latex_accents = { "\xa0": " ", # Unprintable characters } +def collapse_whitespace(s): + """Removes whitespace from string and returns the result. Useful + when whitespace causes errors (e.g. Bibtex) + + :param s: string + :type s: str + """ + logger.debug("Removing whitespace...") + return s.replace(" ","") def crossref_data_to_papis_data(data): if "author" in data.keys(): @@ -379,7 +388,7 @@ def get_cross_ref(doi): res.update(get_citation_info_from_results(record)) # REFERENCE BUILDING - res['ref'] = papis.utils.format_doc(papis.config.get("ref-format"), res) + res['ref'] = collapse_whitespace(papis.utils.format_doc(papis.config.get("ref-format"), res)) # Check if reference field with the same tag already exists documents = papis.api.get_documents_in_lib( diff --git a/papis/document.py b/papis/document.py index b2c019df..f209be71 100644 --- a/papis/document.py +++ b/papis/document.py @@ -16,12 +16,18 @@ def open_in_browser(document): """ global logger url = None - if "url" in document.keys(): + key = papis.config.get("browse-key") + + if "url" in key: url = document["url"] - elif 'doi' in document.keys(): + elif "doc-url" in key: + url = document["doc-url"] + elif "doi" in key: url = 'https://doi.org/' + document['doi'] - elif papis.config.get('doc-url-key-name') in document.keys(): - url = document[papis.config.get('doc-url-key-name')] + elif "isbn" in key: + url = 'https://isbnsearch.org/isbn/' + document['isbn'] + elif key in document.keys(): + url = document[key] else: from urllib.parse import urlencode params = { @@ -88,9 +94,33 @@ def to_bibtex(document): bibtexString += "@%s{%s,\n" % (bibtexType, ref) for bibKey in papis.bibtex.bibtex_keys: if bibKey in document.keys(): - bibtexString += " %s = { %s },\n" % ( - bibKey, papis.bibtex.unicode_to_latex(str(document[bibKey])) - ) + if bibKey == 'journal' and papis.config.get('bibtex-journal-key') in document.keys(): + bibtexString += " %s = { %s },\n" % ( + 'journal', + papis.bibtex.unicode_to_latex( + str(document[papis.config.get('bibtex-journal-key')]) + ) + ) + elif bibKey == 'journal' and papis.config.get('bibtex-journal-key') not in document.keys(): + logger.warning( + "Key '%s' is not present for ref=%s" % ( + papis.config.get('bibtex-journal-key'), + document["ref"] + ) + ) + bibtexString += " %s = { %s },\n" % ( + 'journal', + papis.bibtex.unicode_to_latex( + str(document['journal']) + ) + ) + else: + bibtexString += " %s = { %s },\n" % ( + bibKey, + papis.bibtex.unicode_to_latex( + str(document[bibKey]) + ) + ) bibtexString += "}\n" return bibtexString @@ -356,6 +386,31 @@ class Document(object): """ return self._keys + @property + def has_citations(self): + """Returns string defined in config if keys contains citations + else returns None. + + :returns: String or None + :rtype: str OR None + """ + + if 'citations' in self.keys(): + return papis.config.get('citation-string') + else: + return '' + + def dump(self): + """Return information string without any obvious format + :returns: String with document's information + :rtype: str + + """ + string = "" + for i in self.keys(): + string += str(i)+": "+str(self[i])+"\n" + return string + def load(self): """Load information from info file """ |