-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
76 lines (55 loc) · 2.21 KB
/
utils.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
from PIL import ImageDraw
import datetime
import logging
import re
# create a logger
logger = logging.getLogger("mylogger")
logger.setLevel(logging.DEBUG)
# create a handler to write log messages to a file
file_handler = logging.FileHandler("logs.log")
file_handler.setLevel(logging.DEBUG)
# create a handler to print log messages to the console
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
# create a formatter to include the desired information in the log messages
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s")
# apply the formatter to the handlers
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)
def highlight_pixel(im, x, y):
draw = ImageDraw.Draw(im)
#draw a big red dot at the pixel
draw.ellipse((x-5, y-5, x+5, y+5), fill=(255, 0, 0))
im.show()
def make_time_readable(time):
return datetime.datetime.fromtimestamp(time).strftime('%Y-%m-%d %H:%M:%S')
def make_time_spent_readable(time):
return datetime.datetime.fromtimestamp(time).strftime('%M:%S')
def is_color_different(rgb1, rgb2, level = 30):
r_diff = abs(rgb1[0] - rgb2[0])
g_diff = abs(rgb1[1] - rgb2[1])
b_diff = abs(rgb1[2] - rgb2[2])
logger.info("r_diff: %s, g_diff: %s, b_diff: %s", r_diff, g_diff, b_diff)
if r_diff > level or g_diff > level or b_diff > level:
return True
else:
return False
def print_rgb_color(rgb):
print("\033[38;2;{};{};{}mThis text is in RGB color\033[0m".format(rgb[0], rgb[1], rgb[2]))
logger.info("This text is in RGB color")
# rgb = (255, 0, 0)
# print_rgb_color(rgb)
def is_valid_email(email):
"""
Verify if the given email address is valid.
Returns True if the email address is valid, False otherwise.
"""
# Regular expression for email validation
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
# Use the re.match() function to check if the email matches the pattern
match = re.match(pattern, email)
# If the match is not None, then the email is valid
return match is not None