From 5e931082e405c89c9202acd18a2bfe27659abf7a Mon Sep 17 00:00:00 2001 From: forenta Date: Fri, 29 Dec 2023 20:16:22 +0100 Subject: [PATCH] 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 --- rssingle.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rssingle.py b/rssingle.py index 040c7cd..973450d 100755 --- a/rssingle.py +++ b/rssingle.py @@ -87,6 +87,16 @@ def parse_rss_feed(url) -> feedparser.FeedParserDict: log.warning("Failed to parse RSS feed.") # 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(): 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: log.debug("New feed entry created.") + if not filter_feed_entries(entry): + continue # Skip this entry + fe = fg.add_entry() log.debug("Working on new feed entry..") + try: fe.id(entry["id"]) except KeyError: