Fix item orders and use integrated limit operation;
This commit is contained in:
parent
ea79940e1c
commit
bd3dbc37ea
13
main.py
13
main.py
@ -7,7 +7,7 @@ from flask import Flask, request, abort
|
|||||||
from feedgen.feed import FeedGenerator
|
from feedgen.feed import FeedGenerator
|
||||||
|
|
||||||
from pony import orm
|
from pony import orm
|
||||||
from pony.orm import Required, Optional, Set
|
from pony.orm import Required, Optional, Set, desc
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('settings.ini')
|
config.read('settings.ini')
|
||||||
@ -146,8 +146,11 @@ def by_feed_name(slug):
|
|||||||
gen.link(href=feed.atom_id)
|
gen.link(href=feed.atom_id)
|
||||||
gen.description(feed.description)
|
gen.description(feed.description)
|
||||||
|
|
||||||
count = 0
|
# Take the items by reversed date order. When adding them in the RSS feed,
|
||||||
for item in feed.items.order_by(Item.date):
|
# 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 = gen.add_entry()
|
||||||
fe.id(item.atom_id)
|
fe.id(item.atom_id)
|
||||||
fe.title(item.title)
|
fe.title(item.title)
|
||||||
@ -156,10 +159,6 @@ def by_feed_name(slug):
|
|||||||
date = item.date.replace(tzinfo=timezone.utc)
|
date = item.date.replace(tzinfo=timezone.utc)
|
||||||
fe.published(date)
|
fe.published(date)
|
||||||
|
|
||||||
count += 1
|
|
||||||
if count == 20:
|
|
||||||
break
|
|
||||||
|
|
||||||
return gen.rss_str(pretty=True).decode('utf8')
|
return gen.rss_str(pretty=True).decode('utf8')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user