forked from realgs/streams21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
48 lines (30 loc) · 1.08 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
from datetime import datetime, timedelta
from pathlib import Path
from PIL import Image
def calculate_percent_diff(maxi, mini):
if maxi == mini:
return 100.0
try:
return (maxi / mini) * 100.0 - 100
except ZeroDivisionError:
return 0
def clear_older_data(*lists_to_clear, trigger_list, threshold):
if len(trigger_list) >= threshold:
del trigger_list[0]
for list_to_clear in lists_to_clear:
del list_to_clear[0]
def get_icons(*icon_names, transparent=True):
processed_list = []
for icon_name in icon_names:
path = Path.cwd() / 'icons' / f'{icon_name}-256p.png'
icon_image = Image.open(path)
if transparent:
alpha_channel = icon_image.getchannel('A')
with_alpha = alpha_channel.point(lambda a: 32 if a > 0 else 0)
icon_image.putalpha(with_alpha)
processed_list.append(icon_image)
return processed_list
def get_unix_time(timeframe):
now = datetime.now()
delta = timedelta(minutes=timeframe)
return int((now - delta).timestamp()) * 1000