Spaces:
Sleeping
Sleeping
hmfayyaz commited on
Update fallback_mrz.py
Browse files- src/fallback_mrz.py +18 -47
src/fallback_mrz.py
CHANGED
|
@@ -26,54 +26,25 @@ class FallbackMRZ:
|
|
| 26 |
try:
|
| 27 |
# Basic TD3 parsing (2 lines, 44 chars)
|
| 28 |
# Line 1: P<CCCSURNAME<<NAMES<<<<<<<<<<<<<<<<<<<<<<
|
| 29 |
-
|
| 30 |
-
print(f"Parsing MRZ Line2: '{self.line2}' (len={len(self.line2)})")
|
| 31 |
-
|
| 32 |
-
# Parse line 1 for name information
|
| 33 |
-
if len(self.line1) >= 5: # Minimum length for basic info
|
| 34 |
self.type = self.line1[0:2].replace('<', '')
|
| 35 |
self.country = self.line1[2:5].replace('<', '')
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
self.surname = parts[0].strip('<').strip()
|
| 45 |
-
# Clean the names part - remove extra < characters
|
| 46 |
-
names_part = parts[1].strip('<').strip() if len(parts) > 1 else ""
|
| 47 |
-
# Remove any remaining < characters from names
|
| 48 |
-
self.names = names_part.replace('<', '').strip()
|
| 49 |
-
print(f"Surname: '{self.surname}', Names: '{self.names}'")
|
| 50 |
-
else:
|
| 51 |
-
self.surname = full_name.strip('<').strip()
|
| 52 |
-
self.names = ""
|
| 53 |
-
print(f"Single name: '{self.surname}'")
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
if len(self.line2) >=
|
| 57 |
-
self.number = self.line2[0:9].replace('<', '')
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
if len(self.line2) >= 21:
|
| 66 |
-
self.sex = self.line2[20]
|
| 67 |
-
|
| 68 |
-
if len(self.line2) >= 27:
|
| 69 |
-
self.expiration_date = self.line2[21:27]
|
| 70 |
-
|
| 71 |
-
if len(self.line2) >= 42:
|
| 72 |
-
self.personal_number = self.line2[28:42].replace('<', '')
|
| 73 |
-
|
| 74 |
-
print(f"Passport number: '{self.number}'")
|
| 75 |
-
print(f"Nationality: '{self.nationality}'")
|
| 76 |
-
print(f"Date of birth: '{self.date_of_birth}'")
|
| 77 |
-
print(f"Sex: '{self.sex}'")
|
| 78 |
-
except Exception as e:
|
| 79 |
-
print(f"Error parsing MRZ: {e}")
|
|
|
|
| 26 |
try:
|
| 27 |
# Basic TD3 parsing (2 lines, 44 chars)
|
| 28 |
# Line 1: P<CCCSURNAME<<NAMES<<<<<<<<<<<<<<<<<<<<<<
|
| 29 |
+
if len(self.line1) >= 44:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
self.type = self.line1[0:2].replace('<', '')
|
| 31 |
self.country = self.line1[2:5].replace('<', '')
|
| 32 |
|
| 33 |
+
full_name = self.line1[5:].strip('<')
|
| 34 |
+
if '<<' in full_name:
|
| 35 |
+
parts = full_name.split('<<', 1)
|
| 36 |
+
self.surname = parts[0].replace('<', ' ').strip()
|
| 37 |
+
self.names = parts[1].replace('<', ' ').strip()
|
| 38 |
+
else:
|
| 39 |
+
self.surname = full_name.replace('<', ' ').strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# Line 2: NUM<<<<<DDOB<<SEXP<<<<<<<<<<<<<<<<<<<<<
|
| 42 |
+
if len(self.line2) >= 44:
|
| 43 |
+
self.number = self.line2[0:9].replace('<', '')
|
| 44 |
+
self.nationality = self.line2[10:13].replace('<', '')
|
| 45 |
+
self.date_of_birth = self.line2[13:19]
|
| 46 |
+
self.sex = self.line2[20]
|
| 47 |
+
self.expiration_date = self.line2[21:27]
|
| 48 |
+
self.personal_number = self.line2[28:42].replace('<', '')
|
| 49 |
+
except Exception:
|
| 50 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|