rssingle.py: Filter items with filter_strings from config.yml

Relates to #31, combined #31 and #32 into one PR.

NOTE: Edited to remove typo fix, this will be committed later on.

Signed-off-by: Dom Rodriguez <shymega@shymega.org.uk>
This commit is contained in:
forenta 2023-12-29 20:16:22 +01:00 committed by Dom Rodriguez
parent 62d93c43b9
commit 5e931082e4
No known key found for this signature in database
GPG Key ID: 72DCF1231E54BD43

View File

@ -87,6 +87,16 @@ def parse_rss_feed(url) -> feedparser.FeedParserDict:
log.warning("Failed to parse RSS feed.") log.warning("Failed to parse RSS feed.")
# Now, we could handle gracefully. # Now, we could handle gracefully.
def filter_feed_entries(entry) -> bool:
"""
This function filters feed entries based on strings defined in config.yml.
"""
filter_strings = CONFIG.get("filter_strings", [])
for filter_str in filter_strings:
if filter_str.lower() in entry.get("title", "").lower() or filter_str.lower() in entry.get("summary", "").lower():
log.debug(f"Entry filtered out: {entry['title']}")
return False
return True
def main(): def main():
log.debug("Loading feed list into memory..") log.debug("Loading feed list into memory..")
@ -100,10 +110,14 @@ def main():
for entry in entries[:CONFIG["max_entries"]] if "max_entries" in CONFIG else entries: for entry in entries[:CONFIG["max_entries"]] if "max_entries" in CONFIG else entries:
log.debug("New feed entry created.") log.debug("New feed entry created.")
if not filter_feed_entries(entry):
continue # Skip this entry
fe = fg.add_entry() fe = fg.add_entry()
log.debug("Working on new feed entry..") log.debug("Working on new feed entry..")
try: try:
fe.id(entry["id"]) fe.id(entry["id"])
except KeyError: except KeyError: