-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
33 lines (27 loc) · 877 Bytes
/
utils.py
File metadata and controls
33 lines (27 loc) · 877 Bytes
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
import re
import gzip
import base64
def encode(html: str) -> str:
utf8 = html.encode("utf-8")
gziped = gzip.compress(utf8)
return base64.b64encode(gziped).decode("utf-8")
def decode(base64_str: str) -> str:
gziped = base64.b64decode(base64_str.encode("utf-8"))
utf8 = gzip.decompress(gziped)
return utf8.decode("utf-8")
num_tags = ["numerical", "fill-in-the-blank"]
def find_numerical(tags: list[str]) -> bool:
for tag in tags:
for opt in num_tags:
if opt.startswith(tag):
return True
return False
tag_year_regex = re.compile(r"gate\-?(cse|it|\-)?\-?(\d{4})")
def get_year(string: str) -> [int, None]:
match = tag_year_regex.search(string)
if match:
year = int(match.group(2))
return year
return None
def get_img_format(src: str) -> str:
return "#img_{{{0}}}".format(src)