-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_writer.py
63 lines (49 loc) · 1.4 KB
/
report_writer.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
def write_report(data_list, desc_str, color):
"""
Takes a list of data objects and prints them with specified color
"""
if len(data_list) == 0:
return
color_function = None
if color == 'red':
color_function = red
elif color == 'green':
color_function = green
elif color == 'yellow':
color_function = yellow
if color_function is None:
print("Invalid color specified.")
return
print(color_function(desc_str))
print()
for data in data_list:
print(color_function(data.__str__()))
print()
print("-" * 50)
def write_report_short(data_list, desc_str, color):
"""
Takes a list of data objects and prints their title with specified color
"""
if len(data_list) == 0:
return
color_function = None
if color == 'red':
color_function = red
elif color == 'green':
color_function = green
elif color == 'yellow':
color_function = yellow
if color_function is None:
print("Invalid color specified.")
return
print(color_function(desc_str))
print()
for data in data_list:
print(color_function(data.get_title()))
print("-" * 50)
def green(string):
return "\033[92m" + string + "\033[0m"
def red(string):
return "\033[91m" + string + "\033[0m"
def yellow(string):
return "\033[93m" + string + "\033[0m"