From b161413f137b60617614132d119d963f7cd980e6 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 23 Feb 2023 19:29:31 +0100 Subject: [PATCH] Extract document querying function --- papis-marvin | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/papis-marvin b/papis-marvin index 408a1bb..8f2e6f9 100755 --- a/papis-marvin +++ b/papis-marvin @@ -57,18 +57,24 @@ def get_all_annotations(db, csv) -> Dict: return notes -# TODO warn user/ let him pick with picker if multiple docs found def get_document(db, author, title): - res = db.query(f"author:({author}) title:({title})") + res = query_document(db, author, title) if not res: add_to_database(author, title) - res = db.query(f"author:({author}) title:({title})") - if not res: - logger.warning( - f"Nothing found for {author}: {title}.\nPlease create manually." - ) - return res[0] - return res[0] + res = query_document(db, author, title) + if not res: + logger.warning(f"Nothing found for {author}: {title}.\nPlease create manually.") + return + return res + + +# TODO warn user/ let him pick with picker if multiple docs found +def query_document(db, author, title): + title = strip_string(title) + for query in [f"author:({author}) title:({title})"]: + res = db.query(query) + if len(res) >= 1: + return res[0] def add_to_database(author, title, confirm=True, edit=False): @@ -93,7 +99,6 @@ def get_notefile(db, document) -> str | None: db.update(document) notes_path = os.path.join(str(document.get_main_folder()), document["notes"]) - print(f"{document['title']}: {document['notes']}") if not os.path.exists(notes_path): # TODO reimplement logger: logger.debug("Creating '%s'", notes_path)