# function get_data
# purpose: get the data from a file provided by the user
# preconditons:  user enters filename which can be opened
#   file is formatted as 0 or more lines with URL, keywords delimited with spaces
# postconditions: prompts for filename, error message if file won't open,
#    message of success, returns list of data from file, each element has
#    two string elements, URL and keywords
#    or returns empty list if data was not correctly formatted

#   ask for database file name
#   attempt to open 
#   while open fails, 
#      report failure to user and ask for another name
#   
#   read all the lines from file into list of strings
#   close file
#   for each line in list of strings
#        split into two pieces using comma as delimiter
#   if a line found that does not have correct format
#      report failure, return empty list
#   otherwise
#      report success, return list of data from file

# function do_a_search
# purpose:  search through a list of keywords from database for user-supplied
#   keyword
# precondtions:  list of data from database (all strings), keyword
#   to search for and name of output file
# Postconditions: returns the number of hits found, either 0 if failed search
#   or integer > 0 for successful search
 
#  ask user if they want to be case sensitive
#  if they do not want case sensitivity,  
#     set a flag to False (not case sensitive)
#  otherwise set it to True
#  set hits to empty list
#  for all the entries in the list of data
#      if case sensitivity flag is False, 
#            force both search phrase from user and keyword list from a line of
#              data to lower case
#      if the search phrase is found in the keywords for a line of data
#          add the line of data to the list of hits

#  if hits is still empty
#     report failure
#  otherwise
#     report success
#  return number of hits

# function report_failed
# purpose:  to create a HTML file that reports that for a particular 
#    search phrase, no hits were found
# preconditions:  search phrase and desired output filename
# postcondition:  file created named filename.html, with no hits found message

#   open file
#   output title
#   output table header
#   output message using search phrase and "Not found"
#   output ending html
#   close file

# function report_hits
# purpose:  to create a HTML file that reports the hits in the database
#  for a particular search phrase
# pre-conditions:  list of hits (lines from database including URL and keywords
#   search phrase, and desired output filename
# postconditions:  HTML file with hits in table form

#    open file with desired filename for writing
#    output title line
#    output header with search phrase
#    output top of table and headers for columns

#    for each entry in the list of hits
#       put bold tags around search phrase in keywords string
#       output the link (URL) using an anchor tag, then the keywords string
#         in two columns
#    output end of table and end of file
#    close file
    
#function add_to_log
# purpose: to add a user name and search phrase to end of log file "secret.txt"
# preconditions: username and search phrase
# postconditions: secret.txt is 2 lines longer, username then search phrase
#  open secret.txt in append mode
#  write user name and search phrase on separate lines to file
#  close file
   
# main function
# prolog
# display title
# ask user for user name
# get data from database file
# ask user for keyword search phrase
# ask user for name of file for results
# do the search and get number of hits
# report that the search is done, how many hits and the name of the file that has the results
# add the user and keyword to the log file