Skip to content

Commit a07f461

Browse files
committed
add function to get list of pruefis from xml file
1 parent b66f46d commit a07f461

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/kohlrahbi/ahb/ahb_xml_functions.py

+27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from pathlib import Path
6+
from typing import List
67

78
import tomlkit
89
from efoli import EdifactFormatVersion
@@ -77,3 +78,29 @@ def scrape_xml_pruefis(
7778
input_path = input_path / Path("UTILMD_AHB_Strom_2_1_2024_10_01_2024_09_20.xml")
7879
for pruefi in pruefis:
7980
process_pruefi(pruefi, input_path, output_path, file_type)
81+
82+
83+
def get_pruefidentifikator_list(xml_file_path: Path) -> List[str]:
84+
"""
85+
Reads an XML file and returns a list of all Pruefidentifikator values found in it.
86+
87+
Args:
88+
xml_file_path: Path to the XML file to read
89+
90+
Returns:
91+
List of Pruefidentifikator values found in the file
92+
93+
Raises:
94+
FileNotFoundError: If the XML file does not exist
95+
Exception: If there is an error reading or parsing the XML file
96+
"""
97+
if not xml_file_path.exists():
98+
raise FileNotFoundError(f"XML file not found: {xml_file_path}")
99+
100+
reader = AhbReader(xml_file_path)
101+
ahb = reader.read()
102+
103+
if not isinstance(ahb, Anwendungshandbuch):
104+
raise Exception(f"Expected Anwendungshandbuch instance, got {type(ahb)}")
105+
106+
return sorted(list({awf.pruefidentifikator for awf in ahb.anwendungsfaelle}))

0 commit comments

Comments
 (0)