Skip to content

Commit 059f087

Browse files
authored
✨ allow getting ocr return in CLI (#58)
1 parent 3051e66 commit 059f087

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

mindee/__main__.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import argparse
22
from argparse import Namespace
33
import json
4-
import sys
54
from typing import Dict
65

76
from mindee import Client
@@ -87,7 +86,7 @@ def call_endpoint(args):
8786
if args.product_name == "custom":
8887
parsed_data = doc_to_parse.parse(doc_type, username=args.username)
8988
else:
90-
parsed_data = doc_to_parse.parse(doc_type)
89+
parsed_data = doc_to_parse.parse(doc_type, include_words=args.include_words)
9190

9291
if args.output_type == "raw":
9392
print(json.dumps(parsed_data.http_response, indent=2))
@@ -134,28 +133,35 @@ def parse_args():
134133
dest="%s_api_key" % key_name,
135134
help="API key for %s document endpoint" % key_name,
136135
)
136+
subp.add_argument(
137+
"-w",
138+
"--with-words",
139+
dest="include_words",
140+
action="store_true",
141+
help="Include words in response",
142+
)
137143
subp.add_argument(
138144
"-i",
139145
"--input-type",
140146
dest="input_type",
141147
choices=["path", "file", "base64", "bytes"],
142148
default="path",
143-
help="Specify how to handle the input,\n"
144-
"path: open a path (default).\n"
145-
"file: open as a file handle.\n"
146-
"base64: load the from a base64 encoded text file.\n"
147-
"bytes: load the contents as raw bytes.",
149+
help="Specify how to handle the input.\n"
150+
"- path: open a path (default).\n"
151+
"- file: open as a file handle.\n"
152+
"- base64: load the from a base64 encoded text file.\n"
153+
"- bytes: load the contents as raw bytes.",
148154
)
149155
subp.add_argument(
150156
"-o",
151157
"--output-type",
152158
dest="output_type",
153159
choices=["summary", "raw", "parsed"],
154160
default="summary",
155-
help="Specify how to output the data,\n"
156-
"summary: a basic summary (default)\n"
157-
"raw: the raw HTTP response\n"
158-
"parsed: the validated and parsed data fields\n",
161+
help="Specify how to output the data.\n"
162+
"- summary: a basic summary (default)\n"
163+
"- raw: the raw HTTP response\n"
164+
"- parsed: the validated and parsed data fields\n",
159165
)
160166
subp.add_argument(
161167
"-C",
@@ -175,9 +181,6 @@ def parse_args():
175181
subp.add_argument(dest="path", help="Full path to the file")
176182

177183
parsed_args = parser.parse_args()
178-
if not parsed_args.product_name:
179-
parser.print_help()
180-
sys.exit(1)
181184
return parsed_args
182185

183186

tests/test_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def custom_doc(monkeypatch):
1919
cut_pdf=True,
2020
input_type="path",
2121
output_type="summary",
22+
include_words=False,
2223
path="./tests/data/license_plates/plate.png",
2324
)
2425

@@ -34,6 +35,7 @@ def invoice_doc(monkeypatch):
3435
cut_pdf=True,
3536
input_type="path",
3637
output_type="summary",
38+
include_words=False,
3739
path="./tests/data/invoices/invoice.pdf",
3840
)
3941

0 commit comments

Comments
 (0)