mirror of
https://github.com/tanrax/RSSingle.git
synced 2024-11-21 13:55:41 +01:00
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:
parent
62d93c43b9
commit
5e931082e4
14
rssingle.py
14
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:
|
||||
|
Loading…
Reference in New Issue
Block a user