-
Notifications
You must be signed in to change notification settings - Fork 12
/
pdf417_file_image_reader.py
48 lines (40 loc) · 1.36 KB
/
pdf417_file_image_reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Permite leer desde el pdf417 de la cédula colombiada desde una imagen y
arrojar el resultado parseado en consola
"""
import json
from typing import Tuple
from dbr import *
from src.barcode.colombian_pdf417_decoder import decode_file
def print_usage():
print('Usage: LICENSE_KEY=<license_key> python3 main.py <image_path>')
print('Example: LICENSE_KEY=blablabla python3 main.py ./id_card.png')
def get_args() -> Tuple[str, str]:
if len(sys.argv) < 2:
print('Missing image path')
print_usage()
exit(1)
image_path_ = sys.argv[1]
# Check if image_path is a valid path
if not os.path.isfile(image_path_):
print(f'{image_path_} is not a valid path')
print_usage()
exit(1)
licence_key_ = os.environ['LICENSE_KEY']
if not licence_key_:
print('Please provide a license key in the environment variable LICENSE_KEY')
print_usage()
exit(1)
return image_path_, licence_key_
if __name__ == "__main__":
image_path, licence_key = get_args()
result: str = ''
try:
data = decode_file(image_path, licence_key)
result = json.dumps(data, indent=2, default=lambda o: o.__dict__)
except Exception as e:
result_err = {
'error': str(e)
}
result = json.dumps(result_err, indent=2, default=lambda o: o.__dict__)
print(result)