Extract book comparison into function

This commit is contained in:
Marty Oehme 2023-02-21 14:47:57 +01:00
parent d78c5dd64a
commit 2db5ce4cac
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -12,8 +12,6 @@ import papis.database
import re
import subprocess
# use argument passed to command as file or default file here
def format_entry(row) -> str:
text = f"> {row['HighlightText']}"
@ -26,6 +24,17 @@ def format_entry(row) -> str:
return text
_old_title = ""
def is_same_book(title):
global _old_title
same = _old_title == title
_old_title = title
if same:
return True
return False
def main(fpath, db):
notes = {}
with open(fpath) as f:
@ -34,15 +43,12 @@ def main(fpath, db):
csv = csv.DictReader(f)
title_strip_pattern = re.compile(r"([^\s\w]|_)+")
old_title = ""
note_file = ""
for row in csv:
title_stripped = title_strip_pattern.sub("", row["Title"])
# switch to next book
if old_title != row["Title"]:
old_title = row["Title"]
if not is_same_book(row["Title"]):
documents = db.query(
f"author:({row['Author']}) title:({title_stripped})"
)
@ -89,6 +95,7 @@ def main(fpath, db):
if __name__ == "__main__":
# use argument passed to command as file or default file here
fpath = (
sys.argv[1]
if len(sys.argv) > 1