diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2015-11-22 01:36:39 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2015-11-22 01:36:39 +0100 |
commit | f8cfab4db9e197a403da6c444de1eb295357c9c3 (patch) | |
tree | 1ed6772d966c68f4e457c4a2612ef256d01a4efb /watchnews/rss.py | |
parent | 6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0 (diff) | |
download | watchnews-f8cfab4db9e197a403da6c444de1eb295357c9c3.tar.gz watchnews-f8cfab4db9e197a403da6c444de1eb295357c9c3.zip |
generation of rss feed
Diffstat (limited to 'watchnews/rss.py')
-rw-r--r-- | watchnews/rss.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/watchnews/rss.py b/watchnews/rss.py new file mode 100644 index 0000000..30510c2 --- /dev/null +++ b/watchnews/rss.py @@ -0,0 +1,50 @@ +from . import data +from .web import Difftable + + +from ll.xist import xsc, parse +from ll.xist.ns import xml, rss20 + + +def rss(): + versions = data.Version.raw("""\ +SELECT * +FROM version v +WHERE EXISTS (SELECT 1 + FROM version v2 + WHERE v2.id != v.id + AND v2.item_id == v.item_id + AND v2.created_date < v.created_date) +ORDER BY v.created_date DESC +LIMIT 30""") + + items = [] + for to_version in versions: + from_version = data.Version.select() \ + .where((data.Version.id != to_version.id) & + (data.Version.item == to_version.item) & + (data.Version.created_date < to_version.created_date)) \ + .order_by(data.Version.created_date.desc()) \ + .first() + + difftable = Difftable(to_version, from_version, + inline_style=True).string("utf-8") + items.append(rss20.item( + rss20.title( + "{} - {}".format(to_version.item.feed.title, to_version.title)), + rss20.author(to_version.authors), + rss20.pubDate(to_version.created_date.strftime( + "%a, %d %b %Y %T %z")), + rss20.guid("from={},to={}".format(from_version.id, to_version.id)), + rss20.link(to_version.url), + rss20.description( + xsc.Text(difftable) + ) + )) + return xsc.Frag(xml.XML(), rss20.rss( + rss20.channel( + rss20.title("Watchnews change report"), + *items + ) + ) + ).string("utf-8") |