Skip to content

Commit

Permalink
Provide Invoice2Data class for object oriented usage
Browse files Browse the repository at this point in the history
This will allow using invoice2data in an object oriented way like:

import invoice2data

i2d = invoice2data.Invoice2Data()
i2d.extract_data("foo.pdf")

Signed-off-by: Rafał Miłecki <[email protected]>
  • Loading branch information
Rafał Miłecki committed Feb 19, 2023
1 parent f393d9a commit 4d503e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/invoice2data/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .main import extract_data # noqa: F401
from .main import Invoice2Data
15 changes: 15 additions & 0 deletions src/invoice2data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@
output_mapping = {"csv": to_csv, "json": to_json, "xml": to_xml, "none": None}


class Invoice2Data:
def __init__(self, load_built_in_templates=True):
self.templates = []
if load_built_in_templates:
self.templates += read_templates()


def read_templates(self, path):
self.templates += read_templates(os.path.abspath(path))


def extract_data(self, path, input_module=None):
return extract_data(path, self.templates, input_module)


def extract_data(invoicefile, templates=None, input_module=None):
"""Extracts structured data from PDF/image invoices.
Expand Down

0 comments on commit 4d503e1

Please sign in to comment.