diff --git a/main.py b/main.py index bde0303..b7f15db 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ from flask import Flask, request, abort from feedgen.feed import FeedGenerator from pony import orm -from pony.orm import Required, Optional, Set +from pony.orm import Required, Optional, Set, desc config = configparser.ConfigParser() config.read('settings.ini') @@ -146,8 +146,11 @@ def by_feed_name(slug): gen.link(href=feed.atom_id) gen.description(feed.description) - count = 0 - for item in feed.items.order_by(Item.date): + # Take the items by reversed date order. When adding them in the RSS feed, + # order will be reversed again (first in array will end up last in the + # feed), so explicitly reverse one more time. + items = reversed(feed.items.order_by(desc(Item.date))[:20]) + for item in items: fe = gen.add_entry() fe.id(item.atom_id) fe.title(item.title) @@ -156,10 +159,6 @@ def by_feed_name(slug): date = item.date.replace(tzinfo=timezone.utc) fe.published(date) - count += 1 - if count == 20: - break - return gen.rss_str(pretty=True).decode('utf8')