diff --git a/TODO.md b/TODO.md index 72a3391..73b98d3 100644 --- a/TODO.md +++ b/TODO.md @@ -2,5 +2,4 @@ tags: - frrr --- -+ plugin for xattr -+ plugin for pdf \ No newline at end of file ++ plugin for xattr \ No newline at end of file diff --git a/orvani/cmd.py b/orvani/cmd.py index 0819bfa..85bf384 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -5,7 +5,7 @@ from pathlib import Path from rich.console import Console from rich.table import Table from orvani import OrvaniTag, CONTEXT_FILE, CACHE_FILE, CONTEXTS -from plugins import frontmatter, hashdoubleslash, id3, office +from plugins import frontmatter, hashdoubleslash, id3, office, pdf def mktable(query: str, index: dict, filter=None): console = Console() @@ -98,6 +98,7 @@ def main(): hashdoubleslash.reader(o) id3.reader(o) office.reader(o) + pdf.reader(o) orvani.PLUGINS = args.no_plugins diff --git a/orvani/orvani.py b/orvani/orvani.py index c08c8ac..131b2c2 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -112,6 +112,7 @@ class OrvaniTag: if self.CTX[context_key] != None: context.update( { context_key : []}) for arg in argv: + arg.replace(',', '') for context_key in self.CTX.keys(): if str(arg)[0] in self.CTX.values(): # Schema with prefix diff --git a/orvani/plugins/pdf.py b/orvani/plugins/pdf.py new file mode 100644 index 0000000..c630793 --- /dev/null +++ b/orvani/plugins/pdf.py @@ -0,0 +1,28 @@ +import re +import shutil +from pathlib import Path +from pdfrw import PdfReader, PdfWriter + +NAME = 'pdf' +TYPES = ['.pdf'] +REGEX = r'\s*([@+]\w+|#\w+)' + +def reader(o): + if 'plugins' in o.config: + if NAME not in o.config['plugins']: + return + file = Path(o.path) + suffixes = TYPES + if NAME in o.config: + if 'types' in o.config[NAME]: + suffixes = o.config[NAME]['types'] + if file.suffix in suffixes: + pdf = PdfReader(o.path) + if pdf.Info.Keywords: + tags = re.findall(REGEX, pdf.Info.Keywords.strip()) + note = re.sub(REGEX, '', pdf.Info.Keywords.strip()).replace('(', '').replace(',', '').replace(')', '').strip() + argv = ' '.join(tags).split(' ') + [note] + argv = [x for x in argv if x != ''] + context = o.context(argv) + for context_key in context.keys(): + o.update(o.path, context, context_key) \ No newline at end of file diff --git a/test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf b/test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf new file mode 100644 index 0000000..6e8de79 Binary files /dev/null and b/test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf differ