From 15951d228c6c67a6c8089b739ca875de0133b9e3 Mon Sep 17 00:00:00 2001 From: pictuga Date: Mon, 6 Jul 2020 11:39:08 +0200 Subject: [PATCH] Add :first to NOT sort items by date --- README.md | 1 + morss/morss.py | 11 +++++++++-- www/sheet.xsl | 7 ++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5fbc4f3..6fcddaa 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ The arguments are: - `debug`: to have some feedback from the script execution. Useful for debugging - `force`: force refetch the rss feed and articles - `silent`: don't output the final RSS (useless on its own, but can be nice when debugging) + - `first`: return the feed items in the order they initially appear in the feed (morss ohterwise shows the newest items first) - http server only - `callback=NAME`: for JSONP calls - `cors`: allow Cross-origin resource sharing (allows XHR calls from other servers) diff --git a/morss/morss.py b/morss/morss.py index 74cf39c..b045d13 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -343,8 +343,15 @@ def FeedGather(rss, url, options): if options.cache: max_time = 0 - now = datetime.now(tz.tzutc()) - sorted_items = sorted(rss.items, key=lambda x:x.updated or x.time or now, reverse=True) + if options.first: + # :first to just take the first items in the feed (in sequence) + sorted_items = rss.items + + else: + # otherwise, take the _newest_, i.e. sort by time + now = datetime.now(tz.tzutc()) + sorted_items = sorted(rss.items, key=lambda x:x.updated or x.time or now, reverse=True) + for i, item in enumerate(sorted_items): if time.time() - start_time > lim_time >= 0 or i + 1 > lim_item >= 0: log('dropped') diff --git a/www/sheet.xsl b/www/sheet.xsl index 059f102..b4204d1 100644 --- a/www/sheet.xsl +++ b/www/sheet.xsl @@ -190,7 +190,12 @@ - link and + link of the + + items and