File size: 1,286 Bytes
e0b65ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
import xml.etree.ElementTree as ET
import os
from collections import OrderedDict

# Look in current directory
input_dir = "."
output_file = "screens_log.txt"

# Ordered dictionary: {screen_id: list of sources}
screens = OrderedDict()

# Loop through all XML files in sorted filename order
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)

# Write log grouped by screen ID
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}")