Skip to content

Commit 9c0c7e5

Browse files
committed
rss: publish items in chronological order
1 parent b9294da commit 9c0c7e5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

zulip/integrations/rss/rss-bot

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ for feed_url in feed_urls:
250250

251251
new_hashes = [] # type: List[str]
252252
data = feedparser.parse(feed_url) # type: feedparser.parse
253+
entries = data.entries
254+
if not old_feed_hashes:
255+
# On a first run, pick up the 3 most recent entries. An RSS feed has
256+
# entries in reverse chronological order.
257+
entries = entries[:3]
253258

254-
for entry in data.entries:
259+
for entry in reversed(entries):
255260
entry_hash = compute_entry_hash(entry) # type: str
256261
# An entry has either been published or updated.
257262
entry_time = entry.get(
@@ -265,12 +270,8 @@ for feed_url in feed_urls:
265270
# entries older than some threshold.
266271
continue
267272
if entry_hash in old_feed_hashes:
268-
# We've already seen this. No need to process any older entries.
269-
break
270-
if (not old_feed_hashes) and (len(new_hashes) >= 3):
271-
# On a first run, pick up the 3 most recent entries. An RSS feed has
272-
# entries in reverse chronological order.
273-
break
273+
# We've already seen this.
274+
continue
274275

275276
feed_name = data.feed.title or feed_url # type: str
276277

0 commit comments

Comments
 (0)