Added .gz option

This commit is contained in:
Reuben
2024-11-01 07:06:22 -06:00
committed by GitHub
parent 7d769c7200
commit d204482b53

View File

@@ -3,7 +3,7 @@ import gzip
import xml.etree.ElementTree as ET
import requests
save_as_gz = False # Set to True to save as .gz, False for uncompressed XML
save_as_gz = True # Set to True to save an additional .gz version
tvg_ids_file = os.path.join(os.path.dirname(__file__), 'tvg-ids.txt')
output_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'epg.xml')
@@ -50,15 +50,14 @@ def filter_and_build_epg(urls):
if tvg_id in valid_tvg_ids:
root.append(programme)
tree = ET.ElementTree(root)
tree.write(output_file, encoding='utf-8', xml_declaration=True)
print(f"New EPG saved to {output_file}")
if save_as_gz:
with gzip.open(output_file_gz, 'wb') as f:
tree = ET.ElementTree(root)
tree.write(f, encoding='utf-8', xml_declaration=True)
print(f"New EPG saved to {output_file_gz}")
else:
tree = ET.ElementTree(root)
tree.write(output_file, encoding='utf-8', xml_declaration=True)
print(f"New EPG saved to {output_file}")
urls = [
'https://epgshare01.online/epgshare01/epg_ripper_US1.xml.gz',