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.
This commit is contained in:
Hartmut Goebel
2019-03-29 22:33:23 +01:00
parent e99c18b249
commit fc56be6d70

View File

@ -58,12 +58,15 @@ def read_config(config_file):
def get_feed(feed_url, last_update): def get_feed(feed_url, last_update):
new_entries = 0 new_entries = 0
feed = feedparser.parse(feed_url) feed = feedparser.parse(feed_url)
feed.entries.sort(key=lambda e: e.published_parsed) if last_update:
for entry in feed.entries: entries = [e for e in feed.entries
e = get_entry(entry) if dateutil.parser.parse(e['updated']) > last_update]
if last_update is None or e['updated'] > last_update: else:
new_entries += 1 entries = feed.entries
yield e entries.sort(key=lambda e: e.published_parsed)
for entry in entries:
new_entries += 1
yield get_entry(entry)
return new_entries return new_entries
def get_entry(entry): def get_entry(entry):