Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #2720

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions changeprogramiconsv2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import xml.etree.ElementTree as ET

def update_icon_source(guide_file, programmes_file):
# Parse the guide XML file (where we want to update the icon sources)
guide_tree = ET.parse(guide_file)
guide_root = guide_tree.getroot()

# Parse the programmes XML file (metadata source)
programmes_tree = ET.parse(programmes_file)
programmes_root = programmes_tree.getroot()

# Create a dictionary to map titles to image sources from programmes.xml
title_to_image = {}
for programme in programmes_root.findall('.//programme'):
title = programme.find('title').text
image = programme.find('icon').text
if title and image:
title_to_image[title] = image

# Update the icon source in the guide XML file based on the title match
for programme in guide_root.findall('.//programme'):
title = programme.find('title').text
if title in title_to_image:
icon_element = programme.find('icon')
if icon_element is None:
icon_element = ET.SubElement(programme, 'icon')
icon_element.set('src', title_to_image[title])

# Save the updated guide XML file
guide_tree.write('updated_guide.xml', encoding='utf-8', xml_declaration=True)

# Example usage
update_icon_source('guide.xml', 'programmes.xml')
366 changes: 366 additions & 0 deletions guide.xml

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions programmakerv4
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import xml.etree.ElementTree as ET
from xml.dom import minidom
import os

def extract_program_title_and_icon(xml_file, output_file):
# Parse the input XML file
tree = ET.parse(xml_file)
root = tree.getroot()

# Create a set to track titles that have already been processed
existing_titles = set()

# If the output file exists, read it and extract existing titles
if os.path.exists(output_file):
output_tree = ET.parse(output_file)
output_root = output_tree.getroot()

for programme in output_root.findall('programme'):
title = programme.find('title').text
if title:
existing_titles.add(title)

# Create a new XML structure for the output
if not os.path.exists(output_file):
output_root = ET.Element('programmes')
else:
output_root = output_tree.getroot()

# Loop through each <programme> element in the input XML, excluding <channel> elements
for programme in root.findall('programme'):
title = programme.find('title').text if programme.find('title') is not None else 'No title'
icon = programme.find('icon').get('src') if programme.find('icon') is not None else 'No icon'

# If the title is not already in the output file, add it
if title not in existing_titles:
programme_element = ET.SubElement(output_root, 'programme')
title_element = ET.SubElement(programme_element, 'title')
title_element.text = title
icon_element = ET.SubElement(programme_element, 'icon')
icon_element.text = icon
existing_titles.add(title)

# Convert the output tree to a string and pretty-print it
output_str = ET.tostring(output_root, encoding='utf-8').decode('utf-8')
pretty_str = minidom.parseString(output_str).toprettyxml(indent=" ")

# Write the pretty XML to the output file
with open(output_file, 'w', encoding='utf-8') as f:
f.write(pretty_str)

print(f"XML data has been written to {output_file}")

# Example usage
xml_file = 'meta.xml' # Replace with your XML file path
output_file = 'programmes.xml' # Replace with your desired output file path
extract_program_title_and_icon(xml_file, output_file)
8,293 changes: 8,293 additions & 0 deletions programmes.xml

Large diffs are not rendered by default.

18,986 changes: 18,986 additions & 0 deletions xmltv.xml

Large diffs are not rendered by default.