#!/usr/bin/env python import email.utils import glob import json import xml.etree.ElementTree as ET # This is what we're aiming to generate: # # # # # RSS subscriptions for wes@wezm.net # Sun, 05 May 2024 02:54:31 +0000 # wes@wezm.net # # # # # # # opml = ET.Element("opml") head = ET.SubElement(opml, "head") title = ET.SubElement(head, "title") title.text = "YouTube Subscription" dateCreated = ET.SubElement(head, "dateCreated") dateCreated.text = email.utils.formatdate(timeval=None, localtime=True) body = ET.SubElement(opml, "body") youtube = ET.SubElement(body, "outline", {"title": "YouTube", "text": "YouTube"}) for path in glob.glob("json/*.json"): with open(path) as f: info = json.load(f) ET.SubElement(youtube, "outline", info, type="rss", text=info["title"]) ET.indent(opml) print(ET.tostring(opml, encoding="unicode", xml_declaration=True))