From 6569d0b05d0b2873193a20c823c05e629150f4b6 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 22 Dec 2022 18:32:11 +0100 Subject: [PATCH] Refactor annotations to list of paper,annotations tuples --- extract/extract.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/extract/extract.py b/extract/extract.py index 3c41f62..8b74600 100644 --- a/extract/extract.py +++ b/extract/extract.py @@ -14,7 +14,7 @@ from ...events import PaperChangeEvent, PostCommandEvent from ... import repo from ...utils import resolve_citekey_list -from ...filebroker import DocBroker +from ...content import write_file class ExtractPlugin(PapersPlugin): @@ -33,9 +33,9 @@ class ExtractPlugin(PapersPlugin): def __init__(self, conf, ui): pass self.ui = ui - self.pubsdir = os.path.expanduser(conf["main"]["pubsdir"]) - self.broker = DocBroker(self.pubsdir) self.repository = repo.Repository(conf) + self.pubsdir = os.path.expanduser(conf["main"]["pubsdir"]) + self.broker = self.repository.databroker self.quiet = conf["plugins"].get("extract", {}).get("quiet", False) # self.manual = conf['plugins'].get('git', {}).get('manual', False) # self.force_color = conf['plugins'].get('git', {}).get('force_color', True) @@ -66,16 +66,13 @@ class ExtractPlugin(PapersPlugin): self.to_stdout(all_annotations) def extract(self, papers): - papers_annotated: Dict = {} + papers_annotated = [] for paper in papers: file = self.get_file(paper) try: - papers_annotated[paper.citekey] = self.get_annotations(file) + papers_annotated.append((paper, self.get_annotations(file))) except fitz.FileDataError as e: print(f"ERROR: Document {file} is broken: {e}") - if not self.quiet: - # TODO find pretty print functionality - self.ui.info(f"Extracted annotations from {paper.citekey}") return papers_annotated def gather_papers(self, citekeys): @@ -103,11 +100,13 @@ class ExtractPlugin(PapersPlugin): return annotations def to_stdout(self, annotated_papers): - for citekey, annotations in annotated_papers.items(): + for contents in annotated_papers: + paper = contents[0] + annotations = contents[1] if annotations: - print(f"{citekey}") + print(f"{paper.citekey}") for annot in annotations: - print(f"> \"{annot}\"") + print(f'> "{annot}"') print("")