Extract document querying function
This commit is contained in:
parent
cb1cfe22ab
commit
b161413f13
1 changed files with 15 additions and 10 deletions
25
papis-marvin
25
papis-marvin
|
@ -57,18 +57,24 @@ def get_all_annotations(db, csv) -> Dict:
|
||||||
return notes
|
return notes
|
||||||
|
|
||||||
|
|
||||||
# TODO warn user/ let him pick with picker if multiple docs found
|
|
||||||
def get_document(db, author, title):
|
def get_document(db, author, title):
|
||||||
res = db.query(f"author:({author}) title:({title})")
|
res = query_document(db, author, title)
|
||||||
if not res:
|
if not res:
|
||||||
add_to_database(author, title)
|
add_to_database(author, title)
|
||||||
res = db.query(f"author:({author}) title:({title})")
|
res = query_document(db, author, title)
|
||||||
if not res:
|
if not res:
|
||||||
logger.warning(
|
logger.warning(f"Nothing found for {author}: {title}.\nPlease create manually.")
|
||||||
f"Nothing found for {author}: {title}.\nPlease create manually."
|
return
|
||||||
)
|
return res
|
||||||
return res[0]
|
|
||||||
return res[0]
|
|
||||||
|
# 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):
|
def add_to_database(author, title, confirm=True, edit=False):
|
||||||
|
@ -93,7 +99,6 @@ def get_notefile(db, document) -> str | None:
|
||||||
db.update(document)
|
db.update(document)
|
||||||
|
|
||||||
notes_path = os.path.join(str(document.get_main_folder()), document["notes"])
|
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):
|
if not os.path.exists(notes_path):
|
||||||
# TODO reimplement logger: logger.debug("Creating '%s'", notes_path)
|
# TODO reimplement logger: logger.debug("Creating '%s'", notes_path)
|
||||||
|
|
Loading…
Reference in a new issue