From fc56be6d70b9de99a970ab6cac276aa52b8ea62b Mon Sep 17 00:00:00 2001 From: Hartmut Goebel Date: Fri, 29 Mar 2019 22:33:23 +0100 Subject: [PATCH] Filter entries prior to processing any entry. This saves processing time, esp. since for most installation there should not be so many changes and most times, there will be zero entries to be posted, thus there is not need to process them. --- feediverse.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/feediverse.py b/feediverse.py index eeb3c1b..3226a4f 100755 --- a/feediverse.py +++ b/feediverse.py @@ -58,12 +58,15 @@ def read_config(config_file): def get_feed(feed_url, last_update): new_entries = 0 feed = feedparser.parse(feed_url) - feed.entries.sort(key=lambda e: e.published_parsed) - for entry in feed.entries: - e = get_entry(entry) - if last_update is None or e['updated'] > last_update: - new_entries += 1 - yield e + if last_update: + entries = [e for e in feed.entries + if dateutil.parser.parse(e['updated']) > last_update] + else: + entries = feed.entries + entries.sort(key=lambda e: e.published_parsed) + for entry in entries: + new_entries += 1 + yield get_entry(entry) return new_entries def get_entry(entry):