-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
46 lines (37 loc) · 1.26 KB
/
utils.py
File metadata and controls
46 lines (37 loc) · 1.26 KB
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
import datetime
import typing
from types_mypy import *
from config import RED, RESET, YELLOW
# The universal utilities used by all scripts. #
def toTimestamp(ts: str):
return datetime.datetime.timestamp(datetime.datetime.fromisoformat(ts))
_T1 = typing.TypeVar("_T1")
_T2 = typing.TypeVar("_T2")
def overlap(l1: typing.Iterable[_T1], l2: typing.Iterable[_T2]) -> typing.List[_T1|_T2]:
return list(set(l1) & set(l2))
def exclude(l1: typing.Iterable[_T1], l2: typing.Iterable[_T2]) -> typing.List[_T1|_T2]:
return list(set(l1).difference(set(l2)))
def error(
*args: object,
sep: str | None = " ",
end: str | None = "\n",
file: typing.TextIO | None = None,
flush: bool = False
):
print(f"{RED}ERROR:", *args, sep=sep, end=end, file=file, flush=flush)
print(RESET, end="")
def warning(
*args: object,
sep: str | None = " ",
end: str | None = "\n",
file: typing.TextIO | None = None,
flush: bool = False
):
print(f"{YELLOW}WARNING:", *args, sep=sep, end=end, file=file, flush=flush)
print(RESET, end="")
def convertRGBStrToTuple(RGBStr: str) -> RGBTuple:
return (
int(RGBStr[1:3], 16),
int(RGBStr[3:5], 16),
int(RGBStr[5:7], 16)
)