#!/usr/bin/python3
import xml.etree.ElementTree as ET

# Step 1: Read the variable from the text file
with open('tag.txt', 'r') as file:
    for line in file:
        # Extract the variable and its value
        if line.startswith('TR069_SERVER_URL='):
            TR069_SERVER_URL = line.strip().split('=')[1]

# Step 2: Parse the XML file
tree = ET.parse('tag.xml')
root = tree.getroot()

# Step 3: Find the <port> element and update its value
p8101_element = root.find('P8101')
if p8101_element is not None:
    p8101_element.text = TR069_SERVER_URL  # Replace the port with the value from the variable

# Step 4: Save the updated XML back to a file
tree.write('sample.cnf.xml')

# Print success message
print("XML file updated successfully with the new tr069 server ip value.")

