from app.extract_dates.validate_date import find_smallest_date, validate_date def date_extractor(ocr_list): try: global dob_found dob_found = False dob = None dates_list = [] for index,word in enumerate(ocr_list): date_valid ,pattern = validate_date(word) if date_valid: # valid_pattern = pattern ocr_list.pop(index) # removing elements from list that is being used. dates_list.append(word) if dates_list: # print(dates_list) dob = find_smallest_date(dates_list) # smallest date will be DOB dob_found = True print("DATE OF BIRTH : ", dob) else: print("Date not found") dob_found = False dob = '' return dob_found, dob, ocr_list except Exception as e: print("[Exception in date_extractor] : ", str(e)) dob = '' return dob_found, dob, ocr_list