Add default csv path variable
This commit is contained in:
parent
82f2e7d7df
commit
d4cbc2eb77
1 changed files with 10 additions and 11 deletions
19
papis-marvin
19
papis-marvin
|
@ -9,14 +9,14 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
from typing import Dict
|
||||||
from typing import Dict, List
|
|
||||||
import papis.api
|
import papis.api
|
||||||
import papis.pick
|
import papis.pick
|
||||||
import papis.format
|
import papis.format
|
||||||
import papis.commands.edit
|
import papis.commands.edit
|
||||||
import papis.commands.list
|
import papis.commands.list
|
||||||
import papis.commands.add
|
import papis.commands.add
|
||||||
|
import papis.notes
|
||||||
import papis.config
|
import papis.config
|
||||||
import papis.database
|
import papis.database
|
||||||
import isbnlib
|
import isbnlib
|
||||||
|
@ -25,6 +25,8 @@ import papis.isbn
|
||||||
logger = logging.getLogger("marvin")
|
logger = logging.getLogger("marvin")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
DEFAULT_CSV_PATH = "/home/marty/Nextcloud/Personal/Backups/Journal.csv"
|
||||||
|
|
||||||
|
|
||||||
def main(fpath, db):
|
def main(fpath, db):
|
||||||
with open(fpath) as f:
|
with open(fpath) as f:
|
||||||
|
@ -50,7 +52,7 @@ def get_all_annotations(db, csv) -> Dict:
|
||||||
text = format_entry(row)
|
text = format_entry(row)
|
||||||
|
|
||||||
if note_file and text:
|
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] = []
|
||||||
notes[note_file].append(text)
|
notes[note_file].append(text)
|
||||||
return notes
|
return notes
|
||||||
|
@ -71,6 +73,7 @@ def get_document(db, author, title):
|
||||||
def query_document(db, author, title):
|
def query_document(db, author, title):
|
||||||
title = strip_string(title)
|
title = strip_string(title)
|
||||||
for query in [f"author:({author}) title:({title})"]:
|
for query in [f"author:({author}) title:({title})"]:
|
||||||
|
print(f"query: {query}")
|
||||||
res = db.query(query)
|
res = db.query(query)
|
||||||
if len(res) >= 1:
|
if len(res) >= 1:
|
||||||
return res[0]
|
return res[0]
|
||||||
|
@ -84,7 +87,7 @@ def add_to_database(author, title, confirm=True, edit=False):
|
||||||
except isbnlib.ISBNLibException as e:
|
except isbnlib.ISBNLibException as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
else:
|
else:
|
||||||
logger.info(f"Found: {data}")
|
logger.warning(f"Found: {data}")
|
||||||
if data:
|
if data:
|
||||||
papis_data = papis.isbn.data_to_papis(data[0])
|
papis_data = papis.isbn.data_to_papis(data[0])
|
||||||
papis.commands.add.run([], data=papis_data, confirm=confirm, edit=edit)
|
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):
|
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)
|
||||||
papis.commands.edit.create_notes(document, notes_path)
|
papis.notes.notes_path_ensured(document)
|
||||||
return notes_path
|
return notes_path
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,10 +157,6 @@ def strip_string(title) -> str:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# use argument passed to command as file or default file here
|
# use argument passed to command as file or default file here
|
||||||
fpath = (
|
fpath = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_CSV_PATH
|
||||||
sys.argv[1]
|
|
||||||
if len(sys.argv) > 1
|
|
||||||
else "/home/marty/Nextcloud/Personal/Backups/Journal.csv"
|
|
||||||
)
|
|
||||||
|
|
||||||
main(fpath, papis.database.get())
|
main(fpath, papis.database.get())
|
||||||
|
|
Loading…
Reference in a new issue