def write_phone_results_to_file(customer_phone_dict, filename_results):
    """
    This function writes data to a .csv file.
    :param customer_phone_dict: a dictionary with customer id as key and a tuple as value.
    Tuple includes date, a boolean (True if any phone in comments, False otherwise) and the phone number if
    found (otherwise use 'doesNotFindAPhoneNumber' as default text
    :param filename_results: a string with name and location in disk to write file.
    """
    # Write .csv file to disk
    try:
        with open(filename_results, 'wb') as f_output:
            writer = csv.writer(f_output, delimiter=',')
            for k, v in customer_phone_dict.iteritems():
                date, match_phone, phone_number = v
                writer.writerow(['ApartmentGuide.com', k, match_phone, phone_number])
    except Exception as err:
        print 'Error writing: ' + str(err)


if __name__ == '__main__':
    # Need to change both lines to specify ILS
    filename_txt = "C:/Users/mflores1/dropbox/Mauricio/avln/apt_list_4_month.csv"
    customer_dict = read_text_apartment_list(read_data_from_file(filename_txt))
    # Writes data to disk
    filename_phone_results = "C:/Users/mflores1/dropbox/Mauricio/avln/phone_results_apt_list.csv"
    write_phone_results_to_file(find_phone_in_comment(customer_dict), filename_phone_results)



                        sorted_x[18][1],
                        sorted_x[19][1],
                        sorted_x[20][1],
                        sorted_x[21][1],
                        sorted_x[22][1],
                        sorted_x[23][1],
                        sorted_x[24][1],
                        sorted_x[25][1],
                        sorted_x[26][1],
                        sorted_x[27][1],
                        sorted_x[28][1],
                        sorted_x[29][1],
                        sorted_x[30][1],
                        sorted_x[31][1],
                    ]
                )
    except Exception as err:
        print "Error writing: " + str(err)


# Need to change both lines to select ILS
filename_txt = "C:/Users/mflores1/dropbox/Mauricio/avln/for_rent_4_month.csv"
customer_dict = read_text_for_rent(read_data_from_file(filename_txt))


filename_keywords = "C:/Users/mflores1/dropbox/Mauricio/avln/keywords.txt"
keyword_dict = read_keywords(filename_keywords)
# split_text_in_words(customer_dict, keyword_dict)
filename_result = "C:/Users/mflores1/dropbox/Mauricio/avln/keywords_result.csv"
write_results_to_file(split_text_in_words(customer_dict, keyword_dict), filename_result)