adding guid, pubDate, and execution location option
This commit is contained in:
parent
f2707b8b5b
commit
d741af1a4a
2 changed files with 17 additions and 1 deletions
|
|
@ -18,4 +18,10 @@ LANGUAGE = "en-us"
|
||||||
# example: `feeds` would output your rss feed to www.yoursite.com/feeds/index.xml
|
# 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)
|
# if you leave it None it will be www.yourside.com/index.xml (recommended)
|
||||||
XML_BASE_PATH = ""
|
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
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
|
|
|
||||||
12
generator.py
12
generator.py
|
|
@ -2,11 +2,12 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import platform
|
import platform
|
||||||
|
from uuid import uuid4
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import xml.etree.ElementTree as ET
|
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:
|
class RSSGenerator:
|
||||||
|
|
@ -17,6 +18,9 @@ class RSSGenerator:
|
||||||
|
|
||||||
self.output_path = f"../{XML_BASE_PATH}/index.xml" if XML_BASE_PATH else "../index.xml"
|
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_title = None
|
||||||
self.post_link = None
|
self.post_link = None
|
||||||
self.post_desc = None
|
self.post_desc = None
|
||||||
|
|
@ -118,6 +122,12 @@ class RSSGenerator:
|
||||||
description = ET.SubElement(item, 'description')
|
description = ET.SubElement(item, 'description')
|
||||||
description.text = self.post_desc
|
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):
|
def list_posts(self):
|
||||||
print("\nHere is a list of all your posts:")
|
print("\nHere is a list of all your posts:")
|
||||||
for idx, item in enumerate(self.channel.findall('item')):
|
for idx, item in enumerate(self.channel.findall('item')):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue