From 32d57c79d3a85669464114a1d43249860de81536 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 22 Feb 2023 13:19:34 +0100 Subject: [PATCH] Fix note file creation --- papis-marvin | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/papis-marvin b/papis-marvin index b3f5019..2485399 100755 --- a/papis-marvin +++ b/papis-marvin @@ -5,9 +5,14 @@ # the iOS application 'Marvin Reader'. In the app, export your # annotations as 'csv' format and then point the script to the # resulting file. +import os import sys from typing import Dict, List import papis.api +import papis.pick +import papis.format +import papis.commands.edit +import papis.config import papis.commands.list import papis.database import re @@ -38,12 +43,14 @@ def get_all_annotations(db, csv) -> Dict: f"No papis entry found for Marvin entry - {row['Author']}: {title_stripped}.\nPlease manually create." ) continue - note_file = get_notefile(documents) + # TODO warn user/ let him pick with picker if multiple docs found + doc = documents[0] + note_file = get_notefile(doc) if not note_file: print( f"Found reference entry but no note file for - {row['Author']}: {title_stripped}." ) - manual_papis_entry() + note_file = create_note_file(db, doc) text = format_entry(row) @@ -59,22 +66,29 @@ def get_documents(db, author, title) -> List: def get_notefile(document) -> str | None: - note_file = papis.commands.list.run(notes=True, documents=document) + note_file = papis.commands.list.run(notes=True, documents=[document]) if not note_file: return return str(note_file[0]) -# TODO Implement manual note creation -def manual_papis_entry(): +def create_note_file(db, document): if input(f"Create note file now? [y/N] ") == "y": - # i think instead we need to run the papis.edit cmd with note bool true and maybe editor set to none? - output = subprocess.run( - ["papis", "edit", "-n"], capture_output=True, shell=True + if not document.has("notes"): + notes_name = papis.config.getstring("notes-name") + document["notes"] = papis.format.format(notes_name, document) + document.save() + db.update(document) + + notes_path = os.path.join( + str(document.get_main_folder()), + document["notes"] ) - print(output) - print("NOT IMPLEMENTED: Please create note file manually.") - return + + if not os.path.exists(notes_path): + # TODO reimplement logger: logger.debug("Creating '%s'", notes_path) + papis.commands.edit.create_notes(document, notes_path) + return notes_path else: return