Ejemplo n.º 1
0
def set_color():
    phone_number = request.values.get('From', None)
    color_name = request.values.get('Body', None)
    color_name = clean_name(color_name)

    if color_name == "black":
        response = MessagingResponse()
        response.message("Haha... please use a color that contains light.")
        return str(response)

    if color_name == "previous":
        prev_color = PreviousColorsRedis().getPreviousColor()
        response = MessagingResponse()
        response.message("The previous color was {}".format(clean_name(prev_color)))
        return str(response)

    if color_name == "colors":
        colors_link = 'http://localhost:5000/colors'  # the link of the end point for '/colors'
        response = MessagingResponse()
        response.message("{}".format(colors_link))
        return str(response)

    message = controller.set_color(color_name)
    percent = colorPercent(file,color_name)
    date = firstEntryDate(file)
    response = MessagingResponse()
    response.message(message + " This entry has been chosen " + str(percent) + "% of the time since " + date + "!")
    logging.info("Color " + color_name + " has been set by the phone number " + phone_number + ".")
    writeFile(file,str(phone_number), str(color_name), str(message))
    if colorsRedis().is_color(color_name):
        PreviousColorsRedis().updatePreviousColor(color_name)

    return str(response)
Ejemplo n.º 2
0
def set_color():
    color_name = request.values.get('Body', None)
    color_name = clean_name(color_name)

    if color_name == "black":
        response = MessagingResponse()
        response.message("Haha... please use a color that contains light.")
        return str(response)

    message = controller.set_color(color_name)
    response = MessagingResponse()
    response.message(message)
    return str(response)
Ejemplo n.º 3
0
def go():
    test = "."
    while (test != ""):
        test = input("Please enter a color: ")
        color_name = clean_name(test)
        print(test)
        if color_name == "black":
            print("No black")
        else:
            percent = colorPercent(file, color_name)
            message = controller.set_color(color_name)
            date = firstEntryDate(file)
            writeFile(file, "856-938-4220", str(color_name), str(message))
            print(message + " This entry has been chosen " + str(percent) +
                  "% of the time since " + date + "!")
Ejemplo n.º 4
0
def go():

    r = redis.Redis(host='localhost', port=6379, db=0)

    location = os.path.realpath(
        os.path.join(os.getcwd(), os.path.dirname(__file__)))

    with open(location + '/colors.csv') as colors:
        for line in colors:
            line = line.strip()
            (name, red, green, blue) = line.split(',')

            name = clean_name(name)
            inputVal = str(red + "," + green + "," + blue)

            r.hset("colors", name, inputVal)
Ejemplo n.º 5
0
    def set_color(self, color_name):
        try:
            self.connect()
        except PhueException:
            logging.info("Server unable to connect to the Hue Light")
            return "I'm sorry, but I cannot connect to the Hue Light." \
                   "Please try again later."

        rgb_values = getColor(color_name)

        if rgb_values is None:
            logging.info("Color " + color_name + " was not recognized")
            return "I'm sorry, but I don't recognize " \
                   "the color \"{}\".".format(color_name)

        (r, g, b) = rgb_values.decode("utf-8").split(',')
        r = int(r)
        g = int(g)
        b = int(b)

        converter = Converter()
        print(r, " ", g, " ", b)
        if r == 255 and b == 255 and g == 255:
            saturation_val = 0
            [x, y] = converter.rgb_to_xy(r, g, b)
        else:
            saturation_val = 255
            correction_value = 1.3
            r = ((r / 255) ** (1 / correction_value))
            g = ((g / 255) ** (1 / correction_value))
            b = ((b / 255) ** (1 / correction_value))
            [x, y] = converter.rgb_to_xy(r, g, b)
        try:
            self.light.xy = (x, y)
            self.light.saturation = saturation_val
            logging.info("The light was changed to the color " + color_name)
            return "The light was changed to the color \"{}\"."\
                .format(clean_name(color_name))
        except PhueException:
            logging.info("Server unable to connect to the Hue Light")
            return "I'm sorry, but I cannot connect to the Hue Light." \
                   "Please try again later."
Ejemplo n.º 6
0
def set_color():
    phone_number = request.values.get('From', None)
    color_name = request.values.get('Body', None)
    color_name = clean_name(color_name)

    if color_name == "black":
        response = MessagingResponse()
        response.message("Haha... please use a color that contains light.")
        return str(response)

    message = controller.set_color(color_name)
    percent = colorPercent(file, color_name)
    date = firstEntryDate(file)
    response = MessagingResponse()
    response.message(message + " This entry has been chosen " + str(percent) +
                     "% of the time since " + date + "!")
    logging.info("Color " + color_name + " has been set by the phone number " +
                 phone_number + ".")
    writeFile(file, str(phone_number), str(color_name), str(message))

    return str(response)
Ejemplo n.º 7
0
    def set_color(self, color_name):
        try:
            self.connect()
        except PhueException:
            return "I'm sorry, but I cannot connect to the Hue Light." \
                   "Please try again later."

        rgb_values = self.name_to_color.convert(color_name)

        if rgb_values is None:
            return "I'm sorry, but I don't recognize " \
                   "the color {}".format(color_name)

        (r, g, b) = rgb_values
        converter = Converter()
        [x, y] = converter.rgb_to_xy(r, g, b)
        try:
            self.light.xy = (x, y)
            return "The light was changed to the color {}."\
                .format(clean_name(color_name))
        except PhueException:
            return "I'm sorry, but I cannot connect to the Hue Light." \
                   "Please try again later."
Ejemplo n.º 8
0
def getColor(colorName):
    r = redis.Redis(host='localhost', port=6379, db=0)

    value = r.hget("colors", clean_name(str(colorName)))
    return value
Ejemplo n.º 9
0
def set_color():
    is_random = False
    is_Fuzzy = False
    is_Hex = False
    database = redis.Redis(host='localhost', port=6379, db=0)

    list_of_colors = get_colors_list_from_redis(database)

    phone_number = request.values.get('From', None)
    unclean_color_name = request.values.get('Body', None)
    if unclean_color_name.startswith("#"):
        is_Hex = True
    color_name = clean_name(unclean_color_name)

    if color_name == "black":
        response = MessagingResponse()
        response.message("Haha... please use a color that contains light.")
        return str(response)

    if color_name == "options":
        response = MessagingResponse()
        response.message("\n***Options***\n-------------------------------\n"
                         + "'Options' - list all options for Philips Light functions\n" +
                         "'Colors List' - link to list of color choices\n"
                         "'Random' - chooses a random color for the light")
        return str(response)
    if color_name == "colors list":
        response = MessagingResponse()
        response.message(
            "List of color choices:" + "https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors"
        )
        return str(response)

    try:
        controller.connect()
    except PhueException:
        logging.info("Server unable to connect to the Hue Light")
        response = MessagingResponse()
        response.message("Server unable to connect to the Hue Light")
        return str(response)

    if color_name == "random":
        is_random = True
        color_sum = int(database.get('color_sum').decode('utf-8'), base=10)
        random_int = random.randint(1, color_sum)
        color_name = list_of_colors[random_int]
        database.hincrby('color_totals', 'random', 1)
        database.incr('total', 1)
    else:
        if color_name not in list_of_colors:
            # Checking to see if color is not in list_of_colors due to possible misspelling
            fuzzy_Color = getFuzzyColor(color_name)
            if fuzzy_Color is not None:
                is_Fuzzy = True
                color_name = clean_name(fuzzy_Color)

        if color_name in list_of_colors:
            database.hincrby('color_totals', color_name, 1)
            database.incr('total', 1)

    if is_Hex:
        rgb_values = HEX_to_RGB(unclean_color_name)

    else:
        rgb_values = getColor(color_name)

    if rgb_values is None:
        logging.info("Color " + color_name + " was not recognized")
        response = MessagingResponse()
        response.message("I'm sorry, but I don't recognize the color \"{}\".".format(color_name))
        return str(response)

    [x, y, saturation_val] = convert(rgb_values)

    try:
        controller.light.xy = (x, y)
        controller.light.saturation = saturation_val
        logging.info("The light was changed to the color " + color_name)
        if is_random:
            message = "The light was changed to the color \"{}\". Random was used." \
                .format(clean_name(color_name))
        elif is_Fuzzy:
            message = "We found a color similar to what you requested... The light was changed to the color \"{}\"".format(
                clean_name(color_name))
        elif is_Hex:
            message = "You requested a Hex Color... The light was changed to the Hex \"{}\"".format(
                unclean_color_name)
        else:
            message = "The light was changed to the color \"{}\"." \
                .format(clean_name(color_name))
    except PhueException:
        logging.info("Server unable to connect to the Hue Light")
        response = MessagingResponse()
        response.message("I'm sorry, but I cannot connect to the Hue Light. Please try again later.")
        return str(response)

    if is_random:
        color_name = 'random'
    if is_Hex:
        response = MessagingResponse()
        response.message(message)
        return str(response)

    percent = color_percent(color_name)
    writeFile(file, str(phone_number), str(color_name), str(message))
    date = first_entry_date(file)
    response = MessagingResponse()
    response.message(
        message + " This entry has been chosen {:.1f}".format(percent) + "% of the time since " + date + "!")
    logging.info("Color " + color_name + " has been set by the phone number " + phone_number + ".")

    return str(response)
Ejemplo n.º 10
0
def test_clean_caps():
    assert 'red' == clean_name('Red')
    assert 'red' == clean_name('RED')
    assert 'red' == clean_name('red')
    assert 'red' == clean_name('ReD')
Ejemplo n.º 11
0
def test_clean_whitespace():
    assert 'red' == clean_name('   Red   ')
    assert 'red' == clean_name('\t\tRed\t\t')
    assert 'red' == clean_name('\n\nRed\n\n')
Ejemplo n.º 12
0
def test_clean_punctuation():
    assert 'red' == clean_name('Red.')
    assert 'red' == clean_name('RED!')
    assert 'red' == clean_name('red?')
Ejemplo n.º 13
0
 def is_color(self, colorName):
     key = clean_name(colorName)
     return self.db.hexists("colors", key)
Ejemplo n.º 14
0
 def register_color(self, colorName, r, g, b):
     key = clean_name(colorName)
     value = str(r + "," + g + "," + b)
     self.db.hset("colors", key, value)
Ejemplo n.º 15
0
 def sendMessage(self):
     controller.set_color(clean_name(self.message))