Add default csv path variable

This commit is contained in:
Marty Oehme 2023-08-29 22:41:25 +02:00
parent 82f2e7d7df
commit d4cbc2eb77
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -9,14 +9,14 @@ import os
import sys
import re
import logging
import subprocess
from typing import Dict, List
from typing import Dict
import papis.api
import papis.pick
import papis.format
import papis.commands.edit
import papis.commands.list
import papis.commands.add
import papis.notes
import papis.config
import papis.database
import isbnlib
@ -25,6 +25,8 @@ import papis.isbn
logger = logging.getLogger("marvin")
logger.setLevel(logging.DEBUG)
DEFAULT_CSV_PATH = "/home/marty/Nextcloud/Personal/Backups/Journal.csv"
def main(fpath, db):
with open(fpath) as f:
@ -50,7 +52,7 @@ def get_all_annotations(db, csv) -> Dict:
text = format_entry(row)
if note_file and text:
if not note_file in notes.keys():
if note_file not in notes.keys():
notes[note_file] = []
notes[note_file].append(text)
return notes
@ -60,7 +62,7 @@ def get_document(db, author, title):
res = query_document(db, author, title)
if not res:
add_to_database(author, title)
res = query_document(db, author, title)
res = query_document(db, author, title)
if not res:
logger.warning(f"Nothing found for {author}: {title}.\nPlease create manually.")
return
@ -71,6 +73,7 @@ def get_document(db, author, title):
def query_document(db, author, title):
title = strip_string(title)
for query in [f"author:({author}) title:({title})"]:
print(f"query: {query}")
res = db.query(query)
if len(res) >= 1:
return res[0]
@ -84,7 +87,7 @@ def add_to_database(author, title, confirm=True, edit=False):
except isbnlib.ISBNLibException as e:
logger.error(e)
else:
logger.info(f"Found: {data}")
logger.warning(f"Found: {data}")
if data:
papis_data = papis.isbn.data_to_papis(data[0])
papis.commands.add.run([], data=papis_data, confirm=confirm, edit=edit)
@ -101,7 +104,7 @@ def get_notefile(db, document) -> str | None:
if not os.path.exists(notes_path):
# TODO reimplement logger: logger.debug("Creating '%s'", notes_path)
papis.commands.edit.create_notes(document, notes_path)
papis.notes.notes_path_ensured(document)
return notes_path
@ -154,10 +157,6 @@ def strip_string(title) -> str:
if __name__ == "__main__":
# use argument passed to command as file or default file here
fpath = (
sys.argv[1]
if len(sys.argv) > 1
else "/home/marty/Nextcloud/Personal/Backups/Journal.csv"
)
fpath = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_CSV_PATH
main(fpath, papis.database.get())