# ==============================================================================
"""CSV_HTML :  save a csv file content in a HTML file"""
# ==============================================================================
__author__  = "Philippe Blasi"
__version__ = "1.0"
__date__    = "2023-05-02"
__usage__   = """
User input : <filename> [filename ...]
App output : HTML file with the csv file content in a table"""
# ==============================================================================
from ezCLI import *
# ------------------------------------------------------------------------------
def csv_html(name:str) -> str:
  """save the name csv file content in a HTML file"""
  # ----------------------------------------------------------------------------
  # TODO : construct the new file name with html extension
  #        define the beginning and the end of the html file
  html_begin = """<!DOCTYPE html>
<html lang="fr">
    <head>
        <meta charset="utf-8">
        <title>
            Ressources pour les maths
        </title>
    </head>
    
    <body>"""
  
  html_end = """</body>
</html>
"""
  #        read the file into a matrix (2D array)
  matrix = read_csv(name)
  #        convert each cell into a cell off a html table <td>x</td>
  #        convert each row into a string and add the <tr> </tr> mark up
  # double boucle pour parcourir la matrice

  html_table= ""
  for i in range(10):
    html_table += f"{i} "
  
  #        add the begining and the end of the html file to the result
  result = html_begin + html_table + html_end
  #        save the result into the new html file

  write_txt("exemple.html",result)
  # ----------------------------------------------------------------------------




  
# ------------------------------------------------------------------------------
def parser(command:str) -> str:
  """parse 'command' and return content of provided files with line numbering"""
  names = parse(command); #inspect()
  # TODO : call csv_html for each name file received in the command
  csv_html(names)
  return f"{command} converted"
# ==============================================================================
if __name__ == '__main__':
  userloop(parser, "Enter <filename> [filename ...]")
# ==============================================================================
