-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (25 loc) · 891 Bytes
/
utils.py
File metadata and controls
28 lines (25 loc) · 891 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
"""shared functions"""
import os
import re
def parse_listener_coordinates(listeners):
image_ids = sorted(
list(
set(
im.replace(".on.png", "").replace(".off.png", "").replace(".NA.png", "")
for im in os.listdir("static/icons_crop")
)
)
)
# edit IDs to add image coordinates
for listener in listeners:
id_ = listener["id"]
matching_ids = [imgid for imgid in image_ids if imgid.startswith(id_)]
if len(matching_ids) != 1:
raise ValueError(
f"could not find matching listener for {id_}. Look in static/icons_crop"
)
listener["id"] = matching_ids[0]
matches = re.search(r"([0-9]*)x([0-9]*)y$", matching_ids[0])
listener["x"] = int(matches.group(1))
listener["y"] = int(matches.group(2))
return listeners