From d741af1a4a62ffb682c17038902fdfdb5dfed816 Mon Sep 17 00:00:00 2001 From: Dominic DiTaranto Date: Sat, 18 Apr 2026 21:09:32 -0400 Subject: [PATCH] adding guid, pubDate, and execution location option --- config.py | 6 ++++++ generator.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index bf213e9..2f7f81a 100644 --- a/config.py +++ b/config.py @@ -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 # ######################################################################## diff --git a/generator.py b/generator.py index e374099..86118e3 100644 --- a/generator.py +++ b/generator.py @@ -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')):