mirror of
https://github.com/tanrax/RSSingle.git
synced 2024-11-22 06:05:41 +01:00
Merge pull request #42 from shymega/feature/filter-items
Add functionality for filtering feeds.
This commit is contained in:
commit
1d8d444d2c
@ -6,3 +6,6 @@ max_entries: 2 # Delete this line to get all
|
|||||||
feeds:
|
feeds:
|
||||||
- https://programadorwebvalencia.com/feed/
|
- https://programadorwebvalencia.com/feed/
|
||||||
- https://republicaweb.es/feed/
|
- https://republicaweb.es/feed/
|
||||||
|
filter_strings:
|
||||||
|
- unwanted
|
||||||
|
- exclude_this
|
||||||
|
14
rssingle.py
14
rssingle.py
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user