# This file should contain a function called get_color_code().
# This function should take one argument, a color name,
# and it should return one argument, the hex code of the color,
# if that color exists in our data. If it does not exist, you should
# raise and handle an error that helps both you as a developer,
# for example by logging the request and error, and the user,
# letting them know that their color doesn't exist.

import json
import logging
logging.basicConfig(level=logging.DEBUG, filename='color_check/color_check.log', filemode='w', format='%(asctime)s - %(name)s - %(levelname)s -%("hello")s')

def get_color_code(color_name):
    # this is where you should add your logic to check the color.
    # Open the file at data/css-color-names.json, and return the hex code
    # The file can be considered as JSON format, or as a Python dictionary.

    json_file = open("color_check/data/css-color-names.json") 
    dict_data = json.load(json_file)


    if color_name in dict_data.keys():
        return dict_data[color_name]
    else:
        return " is not a css color!"

    ##maybe change this return

    try:
        return dict_data[color_name]
    except KeyError as error:   
        return " is not a css color!"
        logging.exception("Exception occurred")
#recommit
