adding guid, pubDate, and execution location option

This commit is contained in:
Dominic DiTaranto 2026-04-18 21:09:32 -04:00
parent f2707b8b5b
commit d741af1a4a
2 changed files with 17 additions and 1 deletions

View file

@ -18,4 +18,10 @@ LANGUAGE = "en-us"
# example: `feeds` would output your rss feed to www.yoursite.com/feeds/index.xml
# if you leave it None it will be www.yourside.com/index.xml (recommended)
XML_BASE_PATH = ""
# Set this to true if you plan on executing this from the actual rss generator directory
# this should be false if rss generator is a subdirectory AND
# you plan on calling the generator from the parent directory like:
# `python3 rss_generator/generator.py`
EXECUTE_FROM_RSS_GENERATOR_DIR = False
# ########################################################################

View file

@ -2,11 +2,12 @@ import os
import sys
import subprocess
import platform
from uuid import uuid4
from datetime import datetime
from pathlib import Path
import xml.etree.ElementTree as ET
from config import TITLE, URL, DESCRIPTION, GENERATOR, LANGUAGE, XML_BASE_PATH
from config import TITLE, URL, DESCRIPTION, GENERATOR, LANGUAGE, XML_BASE_PATH, EXECUTE_FROM_RSS_GENERATOR_DIR
class RSSGenerator:
@ -17,6 +18,9 @@ class RSSGenerator:
self.output_path = f"../{XML_BASE_PATH}/index.xml" if XML_BASE_PATH else "../index.xml"
if not EXECUTE_FROM_RSS_GENERATOR_DIR:
self.output_path.replace('../', '')
self.post_title = None
self.post_link = None
self.post_desc = None
@ -118,6 +122,12 @@ class RSSGenerator:
description = ET.SubElement(item, 'description')
description.text = self.post_desc
guid = ET.SubElement(item, 'guid')
guid.text = str(uuid4())
pub_date = ET.SubElement(item, 'pubDate')
pub_date.text = self.now
def list_posts(self):
print("\nHere is a list of all your posts:")
for idx, item in enumerate(self.channel.findall('item')):