File size: 708 Bytes
15de75f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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