-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_fare_products.py
27 lines (23 loc) · 1.13 KB
/
extract_fare_products.py
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
import xml.etree.ElementTree as ET
import os
current_directory = os.getcwd()
# Parse the XML file
tree = ET.parse(os.path.join(current_directory, 'generated', 'nova_stammdaten.xml'))
root = tree.getroot()
# Initialize the dictionary
products = {}
# Extract the desired information
for product_info in root.findall('.//{http://nova.voev.ch/services/v14/vertrieb/vertriebsstammdaten}produktInfo'):
product_nummer = product_info.attrib['{http://nova.voev.ch/services/v14/vertrieb/vertriebsstammdaten}produktNummer']
bez = product_info.find('{http://nova.voev.ch/services/v14/vertrieb/vertriebsstammdaten}produktBezeichnung')
if bez is None:
print(product_nummer)
# Add the extracted data to the dictionary
products[product_nummer] = product_nummer
else:
product_bezeichnung=bez.attrib['{http://nova.voev.ch/services/v14/base}defaultWert']
# Add the extracted data to the dictionary
products[product_nummer] = product_bezeichnung
# Generate the out.py file
with open(os.path.join(current_directory, 'generated', 'out.py'), 'w',encoding='utf-8') as f:
f.write('products = {}\n'.format(products))