diff --git a/papis-marvin b/papis-marvin index 429dfa8..58a3a00 100755 --- a/papis-marvin +++ b/papis-marvin @@ -15,55 +15,67 @@ import subprocess def main(fpath, db): - notes = {} with open(fpath) as f: import csv csv = csv.DictReader(f) - - note_file = "" - for row in csv: - title_stripped = strip_book_title(row["Title"]) - - # switch to next book - if not is_same_book(row["Title"]): - note_file = get_notefile(row["Author"], title_stripped) - if not note_file: - continue - - text = format_entry(row) - - if note_file and text: - if not note_file in notes.keys(): - notes[note_file] = [] - notes[note_file].append(text) + notes = get_all_annotations(db, csv) write_to_files(notes) -def get_documents(author, title) -> List: +def get_all_annotations(db, csv): + notes = {} + note_file = "" + for row in csv: + title_stripped = strip_book_title(row["Title"]) + + # switch to next book + if not is_same_book(row["Title"]): + documents = get_documents(db, row["Author"], title_stripped) + if not documents: + print( + f"No papis entry found for Marvin entry - {row['Author']}: {title_stripped}.\nPlease manually create." + ) + continue + note_file = get_notefile(documents) + if not note_file: + print( + f"Found reference entry but no note file for - {row['Author']}: {title_stripped}." + ) + manual_papis_entry() + + text = format_entry(row) + + if note_file and text: + if not note_file in notes.keys(): + notes[note_file] = [] + notes[note_file].append(text) + return notes + + +# TODO Implement manual note creation +def manual_papis_entry(): + 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 + ) + print(output) + print("NOT IMPLEMENTED: Please create note file manually.") + return + else: + return + + +def get_documents(db, author, title) -> List: return db.query(f"author:({author}) title:({title})") -def get_notefile(author, title) -> str | None: - documents = get_documents(author, title) - if not documents: - print( - f"No papis entry found for Marvin entry - {author}: {title}.\nPlease manually create." - ) - return - note_file = papis.commands.list.run(notes=True, documents=documents) +def get_notefile(document) -> str | None: + note_file = papis.commands.list.run(notes=True, documents=document) if not note_file: - print(f"Found reference entry but no note file for - {author}: {title}.") - if input(f"Create note file now? [y/N] ") == "y": - output = subprocess.run( - ["papis", "edit", "-n"], capture_output=True, shell=True - ) - print(output) - print("NOT IMPLEMENTED: Please create note file manually.") - return - else: - return + return return str(note_file[0]) @@ -121,6 +133,5 @@ if __name__ == "__main__": if len(sys.argv) > 1 else "/home/marty/Nextcloud/Personal/Backups/Journal.csv" ) - db = papis.database.get() - main(fpath, db) + main(fpath, papis.database.get())