File size: 2,671 Bytes
7bbae49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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