Craft Beetle


HTML TO RSS

I keep an up to date changelog and upon fan request I created a script that converts that log to RSS. It doesn't put the actual contents on RSS but it will pop up on your feed as a weekly reminder to come check out my website.


from datetime import datetime
import xml.etree.ElementTree as ET
from xml.dom import minidom

def parse_html_to_rss(html_file, rss_file):
    # Read the HTML file
    with open(html_file, 'r', encoding='utf-8') as file:
        html_content = file.read()

    # Extract the changelog section
    start_index = html_content.find("")
    end_index = html_content.find("")

    if start_index == -1 or end_index == -1:
        print("Changelog section not found.")
        return

    changelog_section = html_content[start_index:end_index]

    # Create the RSS feed structure
    channel = ET.Element('channel')
    title = ET.SubElement(channel, 'title')
    title.text = "Craft Beetle - Change Log Feed"

    link = ET.SubElement(channel, 'link')
    link.text = "https://craftbeetle.com/"  # Replace with your website URL

    description = ET.SubElement(channel, 'description')
    description.text = "Latest updates from the change log"

    details_blocks = changelog_section.split(")
        summary = block.split("")[1].split("")[0].strip()
        date_str = summary
        
        # Convert summary date to RSS Date format
        pub_date = datetime.strptime(date_str, '%Y.%m.%d').strftime('%a, %d %b %Y %H:%M:%S +0000')

        item = ET.Element('item')

        title_item = ET.SubElement(item, 'title')
        title_item.text = f"Update on {summary}"

        link_item = ET.SubElement(item, 'link')
        link_item.text = "https://craftbeetle.com/"  # Replace with the actual link to the changelog
        
        description_item = ET.SubElement(item, 'description')

        updates = []
        categories = block.split("

") for category_block in categories[1:]: # Skip the first split (text before the first

) category = category_block.split("

")[0].strip() items = category_block.split('
  • ')[1:] # Skip the first split (text before the first
  • ) updates.append(f"{category}: " + ', '.join(item.split('
  • ')[0].strip() for item in items)) description_item.text = '\n'.join(updates) pub_date_item = ET.SubElement(item, 'pubDate') pub_date_item.text = pub_date channel.append(item) # Create the XML tree rss = ET.Element('rss', version='2.0') rss.append(channel) # Write to RSS file with pretty printing xml_str = ET.tostring(rss, encoding='utf-8', xml_declaration=True) pretty_xml = minidom.parseString(xml_str).toprettyxml(indent=' ') with open(rss_file, 'w', encoding='utf-8') as f: f.write(pretty_xml) print(f"RSS feed generated successfully: {rss_file}") if __name__ == '__main__': html_file = 'index.html' # Path to your HTML file rss_file = 'rss.xml' # Path to save the RSS file parse_html_to_rss(html_file, rss_file)


    ยฉ 2024-2026 Craft Beetle | All rights reserved

    craftbeetle@protonmail.com | RSS