Spaces:
Build error
Build error
from mrz.checker.td1 import TD1CodeChecker | |
from mrz.checker.td2 import TD2CodeChecker | |
from mrz.checker.td3 import TD3CodeChecker | |
def mrz_engine(mrz_list, lenghtOfChars): | |
try: | |
user_data = {} | |
if lenghtOfChars == 90: | |
check = TD1CodeChecker(f"{mrz_list[0]}\n" | |
f"{mrz_list[1]}\n" | |
f"{mrz_list[2]}" | |
) | |
elif lenghtOfChars == 72: | |
check = TD2CodeChecker(f"{mrz_list[0]}\n" | |
f"{mrz_list[1]}") | |
elif lenghtOfChars == 88: | |
check = TD3CodeChecker(f"{mrz_list[0]}\n" | |
f"{mrz_list[1]}") | |
else: | |
check = False | |
result = bool(check) | |
# print(result) | |
if result: | |
user_data = check.fields() | |
# print(fields.name,fields.surname ) | |
# print(get_country(fields.country)) | |
else: | |
print("FAILED") | |
return user_data | |
except Exception as e: | |
print("[Exception in mrz_engine] : ", str(e)) | |
return user_data | |
def mrz_corrector(capital_strings, lenghtOfCharaters): | |
try: | |
lines = len(capital_strings) | |
if lines == 2 and lenghtOfCharaters not in [72, 88]: | |
safe_check = {72: 3, 88: 3} | |
for index, line in enumerate(capital_strings): | |
if len(line) != safe_check[lenghtOfCharaters]: | |
char_difference = safe_check[lenghtOfCharaters] - len(line) | |
line = line + char_difference * '<' | |
capital_strings[index] = line | |
lenghtOfCharaters = len(capital_strings)*len(line) | |
for index, line in enumerate(capital_strings): | |
if len(line) != 30: | |
char_difference = 30 - len(line) | |
line = line + char_difference * '<' | |
capital_strings[index] = line | |
lenghtOfCharaters = len(capital_strings)*len(line) | |
elif lines == 3 and lenghtOfCharaters != 90: | |
for index, line in enumerate(capital_strings): | |
if len(line) != 30: | |
char_difference = 30 - len(line) | |
line = line + char_difference * '<' | |
capital_strings[index] = line | |
lenghtOfCharaters = len(capital_strings)*len(line) | |
return lenghtOfCharaters, capital_strings | |
except Exception as e: | |
print("[Exception in mrz_corrector] : ", str(e)) | |
lenghtOfCharaters = 0 | |
capital_strings = [] | |
return lenghtOfCharaters, capital_strings |