| from datetime import datetime | |
| def extract_information(text): | |
| words = [w.strip() for w in text.replace(".", "").split("|") if len(w.strip()) > 2] | |
| info = { | |
| "ID": "", | |
| "Name": "", | |
| "Father's Name": "", | |
| "DOB": "", | |
| "ID Type": "PAN" | |
| } | |
| try: | |
| info["Name"] = words[words.index("GOVT OF INDIA") + 1] | |
| info["Father's Name"] = words[words.index("GOVT OF INDIA") + 2] | |
| info["ID"] = words[words.index("Permanent Account Number") + 1] | |
| for w in words: | |
| try: | |
| info["DOB"] = datetime.strptime(w, "%d/%m/%Y") | |
| break | |
| except: | |
| pass | |
| except: | |
| pass | |
| return info | |