Skip to content

Commit 696673c

Browse files
committed
Add method to retrieve UDC names from directory and handle parsing errors
1 parent 5e31d3e commit 696673c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

not1mm/lib/parse_udc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ def parse_udc(self, path: str) -> dict[str, dict[str, str]]:
4848
result[current_section][key] = value
4949

5050
return result
51+
52+
def get_udc_names(self, path: str) -> list[list[str, str]]:
53+
"""
54+
Get a list of UDC names from a directory.
55+
"""
56+
udc_names = []
57+
for file_path in path.iterdir():
58+
if file_path.suffix == ".udc":
59+
try:
60+
udc_data = self.parse_udc(str(file_path))
61+
if "Contest" in udc_data and "DisplayName" in udc_data["Contest"]:
62+
udc_names.append(
63+
[file_path.name, udc_data["Contest"]["DisplayName"]]
64+
)
65+
except Exception as e:
66+
logger.warning(f"Error parsing UDC file {file_path}: {e}")
67+
return udc_names

0 commit comments

Comments
 (0)