################################################################################
# Search through the contact file
# This search will search all fields for matching entry (case insensitive)
################################################################################

def find_contact(list, search):
    search = search.lower()                                     #convert to lower case

    for record in list:                                         #loop through all records
        (lname,fname,addr,email,phone) = record.split('//')     #split on //
        record2 = record.lower()                                #create a lower case version
        if search in record2:
            print(f"Name...: {fname} {lname} ")
            print(f"Address: {addr}  ")
            print(f"Email..: {email} ")
            print(f"Phone..: {phone} ")
             

### main code ############################################################

file  = input("Enter Contact file name: ")
if not file:                                    #if nothing was entered
    file = "data/contact.file"

try:
    contact_file = open(file,'r')               #open the file for reading
except Exception as e:
    print(F"Could not open file - {e}")
    exit()

list = contact_file.readlines()                 #read entire file into a list
contact_file.close()                            #close the file

search = input("Search for: ")                  #the search criterea 

find_contact(list, search)                      #call the find_contact function