| import xml.etree.ElementTree as ET |
| import os |
| from collections import OrderedDict |
|
|
| |
| input_dir = "." |
| output_file = "screens_log.txt" |
|
|
| |
| screens = OrderedDict() |
|
|
| |
| for file in sorted(os.listdir(input_dir)): |
| if not file.lower().endswith(".xml"): |
| continue |
|
|
| path = os.path.join(input_dir, file) |
| tree = ET.parse(path) |
| root = tree.getroot() |
|
|
| for screen in root.findall("SCREEN"): |
| screen_id = screen.attrib.get("ID", "UNKNOWN").strip() |
|
|
| if screen_id not in screens: |
| screens[screen_id] = [] |
|
|
| for src in screen.findall("SOURCE"): |
| source_text = (src.text or "").strip() |
| if source_text and source_text not in screens[screen_id]: |
| screens[screen_id].append(source_text) |
|
|
| |
| with open(output_file, "w", encoding="utf-8") as f: |
| for screen_id, sources in screens.items(): |
| f.write(f"[{screen_id}]\n") |
| for src in sources: |
| f.write(f" <SOURCE>{src}</SOURCE>\n") |
| f.write("\n") |
|
|
| print(f"? Collected screens from all XMLs in current directory, keeping order by file and entry. Log written to {output_file}") |
|
|