Fix note file creation
This commit is contained in:
parent
46ea119204
commit
32d57c79d3
1 changed files with 25 additions and 11 deletions
36
papis-marvin
36
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue