Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions mindee/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
from argparse import Namespace
import json
import sys
from typing import Dict

from mindee import Client
Expand Down Expand Up @@ -87,7 +86,7 @@ def call_endpoint(args):
if args.product_name == "custom":
parsed_data = doc_to_parse.parse(doc_type, username=args.username)
else:
parsed_data = doc_to_parse.parse(doc_type)
parsed_data = doc_to_parse.parse(doc_type, include_words=args.include_words)

if args.output_type == "raw":
print(json.dumps(parsed_data.http_response, indent=2))
Expand Down Expand Up @@ -134,28 +133,35 @@ def parse_args():
dest="%s_api_key" % key_name,
help="API key for %s document endpoint" % key_name,
)
subp.add_argument(
"-w",
"--with-words",
dest="include_words",
action="store_true",
help="Include words in response",
)
subp.add_argument(
"-i",
"--input-type",
dest="input_type",
choices=["path", "file", "base64", "bytes"],
default="path",
help="Specify how to handle the input,\n"
"path: open a path (default).\n"
"file: open as a file handle.\n"
"base64: load the from a base64 encoded text file.\n"
"bytes: load the contents as raw bytes.",
help="Specify how to handle the input.\n"
"- path: open a path (default).\n"
"- file: open as a file handle.\n"
"- base64: load the from a base64 encoded text file.\n"
"- bytes: load the contents as raw bytes.",
)
subp.add_argument(
"-o",
"--output-type",
dest="output_type",
choices=["summary", "raw", "parsed"],
default="summary",
help="Specify how to output the data,\n"
"summary: a basic summary (default)\n"
"raw: the raw HTTP response\n"
"parsed: the validated and parsed data fields\n",
help="Specify how to output the data.\n"
"- summary: a basic summary (default)\n"
"- raw: the raw HTTP response\n"
"- parsed: the validated and parsed data fields\n",
)
subp.add_argument(
"-C",
Expand All @@ -175,9 +181,6 @@ def parse_args():
subp.add_argument(dest="path", help="Full path to the file")

parsed_args = parser.parse_args()
if not parsed_args.product_name:
parser.print_help()
sys.exit(1)
return parsed_args


Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def custom_doc(monkeypatch):
cut_pdf=True,
input_type="path",
output_type="summary",
include_words=False,
path="./tests/data/license_plates/plate.png",
)

Expand All @@ -34,6 +35,7 @@ def invoice_doc(monkeypatch):
cut_pdf=True,
input_type="path",
output_type="summary",
include_words=False,
path="./tests/data/invoices/invoice.pdf",
)

Expand Down