summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Gallo <aamsgallo@gmail.com>2021-03-06 12:34:49 +0100
committerAlejandro Gallo <aamsgallo@gmail.com>2021-03-06 12:34:49 +0100
commite9d24582d8c4b28f9c5725ceb1211d5f5f98ffba (patch)
tree65454ff0bd165bf648138267e72fc526718d5713
parent00a07d43694b3642614044c50b3b2dc432c7a095 (diff)
Add paps bibtex filter-cited command
-rw-r--r--CHANGELOG.md1
-rw-r--r--papis/commands/bibtex.py28
2 files changed, 27 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43768b2e..aaffcbea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@ VERSION v0.12
## `papis bibtex`
- Add `import` command to import bibtex files as papis documents
into the library.
+- Add `filter-cited`.
## `papis exec`
- Add command `exec` to run python scripts in the environment of the
diff --git a/papis/commands/bibtex.py b/papis/commands/bibtex.py
index 996929d5..7ec7db10 100644
--- a/papis/commands/bibtex.py
+++ b/papis/commands/bibtex.py
@@ -377,14 +377,38 @@ def _doctor(ctx: click.Context, key: List[str]) -> None:
logger.info('\tmissing: %s', k)
+@cli.command('filter-cited')
+@click.help_option('-h', '--help')
+@click.option('-f', '--file', '_files',
+ help="Text file to check for references",
+ multiple=True, required=True, type=str)
+@click.pass_context
+def _filter_cited(ctx: click.Context, _files: List[str]) -> None:
+ """
+ Filter cited documents from the read bib file
+ e.g.
+ papis bibtex read main.bib filter-cited -f main.tex save cited.bib
+ """
+ found = []
+
+ for f in _files:
+ with open(f) as fd:
+ text = fd.read()
+ for doc in ctx.obj['documents']:
+ if re.search(doc["ref"], text):
+ found.append(doc)
+
+ logger.info('%s documents cited', len(found))
+ ctx.obj["documents"] = found
+
+
@cli.command('iscited')
@click.help_option('-h', '--help')
@click.option('-f', '--file', '_files',
help="Text file to check for references",
multiple=True, required=True, type=str)
-@papis.cli.all_option()
@click.pass_context
-def _iscited(ctx: click.Context, _files: List[str], _all: bool) -> None:
+def _iscited(ctx: click.Context, _files: List[str]) -> None:
"""
Check which documents are not cited
e.g. papis bibtex iscited -f main.tex -f chapter-2.tex