Closed lamhoangtung closed 4 years ago
Hi, what's up!
Yes, there should be no problem. In fact, MRZ Generator was modified so that it was not necessary to instantiate XXXCodeGenerator several times to obtain many MRZ Codes. I think this option is more fast and efficient than creating multiple instances. It's only necessary to modify the properties with the desired values and print the code at any time. You can see this in example passport_can.py:
from mrz.generator.td3 import *
td3_generator = TD3CodeGenerator("P", # Document type Normally 'P' for passport
"GB", # Country 3 letters code or country name
"MARTIN", # Surname(s) Special characters will be transliterated
"SARAH", # Given name(s) Special characters will be transliterated
"980XG47", # Passport number
"GBR", # Nationality 3 letter code or country name
"850101", # Birth date YYMMDD
"F", # Genre Male: 'M', Female: 'F' or Undefined 'X'
"261228", # Expiry date YYMMDD
"ID88933477") # Id number Not mandatory field
print(td3_generator)
print("\n")
td3_generator.country_code = "CAN"
td3_generator.document_number = "ZE000509"
td3_generator.nationality = "CAN"
td3_generator.expiry_date = "230114"
td3_generator.optional_data = ""
print(td3_generator)
So all you need is to have the necessary collections and/or databases and create your own randomization engine.
A very basic example for to print 100 random TD1 MRZ codes:
from mrz.generator.td1 import *
from datetime import date
from random import choice
td1_mrz = TD1CodeGenerator("ID", "ESP", "BAA000589", "800101", "F", "250101",
"ESP", "ESPAÑOLA ESPAÑOLA", "CARMEN", "99999999R")
countries = countries_list()
genders = ("M", "F")
births = [date.fromordinal(i).strftime("%y%m%d") for i in range(date(2000, 1, 1).toordinal(), date(2001, 1, 1).toordinal())]
expiry = [date.fromordinal(i).strftime("%y%m%d") for i in range(date(2021, 1, 1).toordinal(), date(2022, 1, 1).toordinal())]
names = ["John", "Pedro", "Gisselle", "Angelina", "Alphonse"]
surnames = ["Smith", "Sanchez", "Lee", "Cardin", "Schneider", "Weber"]
for i in range(100):
td1_mrz.country_code = td1_mrz.nationality = choice(countries)
td1_mrz.birth_date = choice(births)
td1_mrz.sex = choice(genders)
td1_mrz.expiry_date = choice(expiry)
td1_mrz.surname = "%s %s" % (choice(surnames), choice(surnames))
td1_mrz.given_names = choice(names)
print(td1_mrz)
print()
Output:
IDSVNBAA000589599999999R<<<<<<
0006194M2109147SVN<<<<<<<<<<<1
CARDIN<WEBER<<PEDRO<<<<<<<<<<<
IDVCTBAA000589599999999R<<<<<<
0002071M2103293VCT<<<<<<<<<<<7
WEBER<LEE<<ANGELINA<<<<<<<<<<<
[...]
IDKHMBAA000589599999999R<<<<<<
0001203M2102137KHM<<<<<<<<<<<1
SMITH<LEE<<JOHN<<<<<<<<<<<<<<<
I hope I've helped. Regards!
Thanks you for such a quick and details answer.
Hi, thanks for the amazing work.
Can I use this to generate unlimited random MRZ ?