Fix note file creation

This commit is contained in:
Marty Oehme 2023-02-22 13:19:34 +01:00
parent 46ea119204
commit 32d57c79d3
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -5,9 +5,14 @@
# the iOS application 'Marvin Reader'. In the app, export your # the iOS application 'Marvin Reader'. In the app, export your
# annotations as 'csv' format and then point the script to the # annotations as 'csv' format and then point the script to the
# resulting file. # resulting file.
import os
import sys import sys
from typing import Dict, List from typing import Dict, List
import papis.api import papis.api
import papis.pick
import papis.format
import papis.commands.edit
import papis.config
import papis.commands.list import papis.commands.list
import papis.database import papis.database
import re 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." f"No papis entry found for Marvin entry - {row['Author']}: {title_stripped}.\nPlease manually create."
) )
continue 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: if not note_file:
print( print(
f"Found reference entry but no note file for - {row['Author']}: {title_stripped}." 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) text = format_entry(row)
@ -59,22 +66,29 @@ def get_documents(db, author, title) -> List:
def get_notefile(document) -> str | None: 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: if not note_file:
return return
return str(note_file[0]) return str(note_file[0])
# TODO Implement manual note creation def create_note_file(db, document):
def manual_papis_entry():
if input(f"Create note file now? [y/N] ") == "y": 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? if not document.has("notes"):
output = subprocess.run( notes_name = papis.config.getstring("notes-name")
["papis", "edit", "-n"], capture_output=True, shell=True 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.") if not os.path.exists(notes_path):
return # TODO reimplement logger: logger.debug("Creating '%s'", notes_path)
papis.commands.edit.create_notes(document, notes_path)
return notes_path
else: else:
return return