-
Notifications
You must be signed in to change notification settings - Fork 1
/
text_test.py
108 lines (78 loc) · 3.12 KB
/
text_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import colorsys
import json
text_1 = "set brightness and Saturation to 20% and hue to 30%"
text_2 = "Set Brightness to 10% hue to 20% and saturation to 30%"
text_3 = "set brightness saturation and Hue to 20%"
text_4 = "set brightness to 20% and color to red"
text_5 = "set brightness to 100% and color to red"
text_6 = "set brightness to 100% and color to red and green"
text_7 = "set color to red and brightness to 10%"
text_20 = "set brightness and Saturation to 20% and hue to 30% red"
set_list = ["hue", "saturation", "brightness"]
color_list = ["red","green","blue","yellow"]
Dict = dict({"hue": None, "saturation": None, "brightness": None, "color":None})
command = text_7
command = command.split(" ")
set_flag = False
i = 0
ii = 0
color_flag_error = False
hsv_flag = False
rbg_flag = False
temp = []
for word in command:
if "set"==word or "Set"==word:
#print("set flag true")
set_flag = True
if set_flag:
if word.lower() in set_list:
temp.append(word.lower())
#print(" added", word)
if word.lower() in color_list:
if Dict["color"] != None:
print("error. too many colors. ")
color_flag_error = True
Dict["color"]=word.lower()
if "%" in word:
digit = word.split("%")
digit = float(digit[0])
for item in temp:
if item == "hue":
Dict["hue"] = digit/100
hsv_flag = True
if item == "saturation":
Dict["saturation"] = digit/100
hsv_flag = True
if item == "brightness":
Dict["brightness"] = digit/100
temp = []
print(command)
if (Dict["color"]) !=None and (Dict["hue"]!=None and Dict["saturation"]!=None):
print("error")
elif Dict["color"]!=None:
if Dict["color"] == "red":
#print(colorsys.rgb_to_hsv(int(255*float(Dict["brightness"])), 0, 0))
(hue, saturation,value) = colorsys.rgb_to_hsv(255, 0, 0)
brightness = Dict["brightness"]
elif Dict["color"] == "green":
#print(colorsys.rgb_to_hsv(int(255*float(Dict["brightness"])), 0, 0))
(hue, saturation,value) = colorsys.rgb_to_hsv(0, 255, 0)
brightness = Dict["brightness"]
elif Dict["color"] == "blue":
#print(colorsys.rgb_to_hsv(int(255*float(Dict["brightness"])), 0, 0))
(hue, saturation,value) = colorsys.rgb_to_hsv(0, 0, 255)
brightness = Dict["brightness"]
elif Dict["color"] == "yellow":
#print(colorsys.rgb_to_hsv(int(255*float(Dict["brightness"])), 0, 0))
(hue, saturation,value) = colorsys.rgb_to_hsv(255, 255, 0)
brightness = Dict["brightness"]
if color_flag_error == False:
print("hue:",hue,"saturation:",saturation,"brightness:",brightness)
# write data
elif Dict["hue"]!=None or Dict["saturation"]!=None :
hue = Dict["hue"]
saturation = Dict["saturation"]
brightness = Dict["brightness"]
print(hue,saturation,brightness)
#print(Dict)
#color_flag_error = False