Update config

This commit is contained in:
Andros Fenollosa 2022-06-19 18:24:55 +02:00
parent 596d981816
commit 43b9a1e3b0

View File

@ -27,8 +27,6 @@ FEEDS = []
CFG = None CFG = None
def setup_logging() -> None: def setup_logging() -> None:
""" """
This function intiialises the logger framework. This function intiialises the logger framework.
@ -39,17 +37,21 @@ def setup_logging() -> None:
log.setLevel(LOG_LEVEL) log.setLevel(LOG_LEVEL)
ch = logging.StreamHandler(sys.stderr) ch = logging.StreamHandler(sys.stderr)
ch.setLevel(LOG_LEVEL) ch.setLevel(LOG_LEVEL)
ch.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) ch.setFormatter(
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
)
log.addHandler(ch) log.addHandler(ch)
return None return None
def get_url_from_feed(config): def get_url_from_feed(config):
""" """
This function returns the URL from a feed. This function returns the URL from a feed.
""" """
return config["url"] + "/" + config["output"] return config["url"] + "/" + config["output"]
def init_feed() -> None: def init_feed() -> None:
""" """
This function initialises the RSS feed with the This function initialises the RSS feed with the
@ -65,9 +67,9 @@ def init_feed() -> None:
fg.id(get_url_from_feed(CONFIG)) fg.id(get_url_from_feed(CONFIG))
fg.title(CONFIG["title"]) fg.title(CONFIG["title"])
fg.generator("RSSingle/v1.0.0") fg.generator("RSSingle/v1.0.0")
fg.link(get_url_from_feed(CONFIG), rel="self") fg.link(href=get_url_from_feed(CONFIG), rel="self")
fg.subtitle(CONFIG["description"]) fg.subtitle(CONFIG["description"])
fg.language('en') fg.language("en")
except: except:
log.error("Error initialising the feed!") log.error("Error initialising the feed!")
sys.exit(1) sys.exit(1)
@ -90,16 +92,10 @@ def parse_rss_feed(url) -> feedparser.FeedParserDict:
def main(): def main():
log.debug("Loading feed list into memory..") log.debug("Loading feed list into memory..")
feeds = None
with open(CONFIG_PATH, "r") as infile:
feeds = infile.read().splitlines()
log.debug("Iterating over feed list..") log.debug("Iterating over feed list..")
for feed in feeds:
FEEDS.append(feed)
log.debug("Iterating over [input] feeds...") for feed in CONFIG["feeds"]:
for feed in FEEDS:
rss = parse_rss_feed(feed) rss = parse_rss_feed(feed)
entries = rss.get("entries") entries = rss.get("entries")
log.debug("Iterating over [input] feed entries..") log.debug("Iterating over [input] feed entries..")
@ -130,7 +126,7 @@ def main():
# When we have a empty link attribute, this isn't ideal # When we have a empty link attribute, this isn't ideal
# to set a default value.. :/ # to set a default value.. :/
log.warning("Empty link attribute, defaulting..") log.warning("Empty link attribute, defaulting..")
fe.link(href='about:blank') fe.link(href="about:blank")
try: try:
if entry["sources"]["authors"]: if entry["sources"]["authors"]:
@ -149,8 +145,7 @@ def main():
# Sometimes we don't have ANY author attributes, so we # Sometimes we don't have ANY author attributes, so we
# have to set a dummy attribute. # have to set a dummy attribute.
log.warning("Empty authors attribute, defaulting..") log.warning("Empty authors attribute, defaulting..")
fe.author({"name": "Unspecified", fe.author({"name": "Unspecified", "email": "unspecified@example.com"})
"email": "unspecified@example.com"})
try: try:
if entry["summary"]: if entry["summary"]:
@ -165,8 +160,7 @@ def main():
# have to set an empty value. # have to set an empty value.
# This is pretty useless for a feed, so hopefully we # This is pretty useless for a feed, so hopefully we
# don't have to do it often! # don't have to do it often!
log.warning( log.warning("Empty description OR summary attribute, defaulting..")
"Empty description OR summary attribute, defaulting..")
fe.description("Unspecified") fe.description("Unspecified")
fe.summary("Unspecified") fe.summary("Unspecified")
@ -193,7 +187,7 @@ if __name__ == "__main__":
global CONFIG global CONFIG
with open('config.yml', 'r') as file: with open("config.yml", "r") as file:
CONFIG = yaml.safe_load(file) CONFIG = yaml.safe_load(file)
log.debug("Assiging variables..") log.debug("Assiging variables..")
@ -226,4 +220,4 @@ if __name__ == "__main__":
log.debug("Begin processing feeds...") log.debug("Begin processing feeds...")
main() main()
fg.rss_file(FEED_OUT_PATH) fg.rss_file(FEED_OUT_PATH)