You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.9 KiB

import os
from io import BytesIO
from datetime import datetime
from xml.etree import ElementTree
tree = ElementTree.ElementTree().parse('index.html')
sbbsbase = tree.find('./head/link[@rel="canonical"]').attrib['href']
feed = ElementTree.Element('rss', version='2.0')
channel = ElementTree.SubElement(feed, 'channel')
title = ElementTree.SubElement(channel, 'title')
title.text = 'software being broken showcase'
link = ElementTree.SubElement(channel, 'link')
link.text = sbbsbase
description = ElementTree.SubElement(channel, 'description')
description.text = 'just a showcase of software being broken :)'
language = ElementTree.SubElement(channel, 'language')
language.text = 'en-us'
file = BytesIO()
def parse_file(i):
tree = ElementTree.ElementTree().parse(i)
item = ElementTree.Element('item')
title = ElementTree.SubElement(item, 'title')
title.text = tree.find('body').find('h1').text
link = ElementTree.SubElement(item, 'link')
link.text = tree.find('./head/link[@rel="canonical"]').attrib['href']
guid = ElementTree.SubElement(item, 'guid')
guid.text = f'sbbs/{os.path.splitext(i)[0]}'
description = ElementTree.SubElement(item, 'description')
ElementTree.ElementTree(tree.find('./body/div[@class="content"]')).write(file, 'utf-8', method='html')
description.text = file.getvalue().decode()
return (datetime.fromisoformat(tree.find('./head/meta[@name="created"]').attrib['content']), item)
for date, i in sorted(map(parse_file, filter(lambda i: i not in ('index.html', 'index.xml'), os.listdir('.'))), reverse=True, key=lambda i: i[0]):
ctime = date.ctime()
pubdate = ElementTree.SubElement(i, 'pubDate')
pubdate.text = f"{ctime[0:3]}, {} {ctime[4:7]} {date.strftime(' %Y %H:%M:%S %z')}"
ElementTree.ElementTree(feed).write('index.xml', 'utf-8', True)