More ordering options
continuous-integration/drone/push Build was killed Details

master
pictuga 2022-01-23 12:27:07 +01:00
parent 4d6d3c9239
commit a01258700d
3 changed files with 25 additions and 15 deletions

View File

@ -392,10 +392,11 @@ The list of arguments can be obtained by running `morss --help`
``` ```
usage: morss [-h] [--post STRING] [--xpath XPATH] usage: morss [-h] [--post STRING] [--xpath XPATH]
[--format {rss,json,html,csv}] [--search STRING] [--clip] [--format {rss,json,html,csv}] [--search STRING] [--clip]
[--indent] [--cache] [--force] [--proxy] [--newest] [--firstlink] [--indent] [--cache] [--force] [--proxy]
[--resolve] [--items XPATH] [--item_link XPATH] [--order {first,last,newest,oldest}] [--firstlink] [--resolve]
[--item_title XPATH] [--item_content XPATH] [--item_time XPATH] [--items XPATH] [--item_link XPATH] [--item_title XPATH]
[--nolink] [--noref] [--silent] [--item_content XPATH] [--item_time XPATH] [--nolink] [--noref]
[--silent]
url url
Get full-text RSS feeds Get full-text RSS feeds
@ -403,7 +404,7 @@ Get full-text RSS feeds
positional arguments: positional arguments:
url feed url url feed url
optional arguments: options:
-h, --help show this help message and exit -h, --help show this help message and exit
--post STRING POST request --post STRING POST request
--xpath XPATH xpath rule to manually detect the article --xpath XPATH xpath rule to manually detect the article
@ -422,8 +423,9 @@ action:
articles' content), so as to save time articles' content), so as to save time
--force force refetch the rss feed and articles --force force refetch the rss feed and articles
--proxy doesn't fill the articles --proxy doesn't fill the articles
--newest return the feed items in chronological order (morss --order {first,last,newest,oldest}
ohterwise shows the items by appearing order) order in which to process items (which are however NOT
sorted in the output)
--firstlink pull the first article mentioned in the description --firstlink pull the first article mentioned in the description
instead of the default link instead of the default link
--resolve replace tracking links with direct links to articles --resolve replace tracking links with direct links to articles

View File

@ -328,14 +328,20 @@ def FeedGather(rss, url, options):
if options.cache: if options.cache:
max_time = 0 max_time = 0
if options.newest: # sort
# :newest take the newest items (instead of appearing order) sorted_items = list(rss.items)
now = datetime.now(tz.tzutc())
sorted_items = sorted(rss.items, key=lambda x:x.updated or x.time or now, reverse=True)
else: if options.order == 'last':
# default behavior, take the first items (in appearing order) # `first` does nothing from a practical standpoint, so only `last` needs
sorted_items = list(rss.items) # to be addressed
sorted_items = reversed(sorted_items)
elif options.order in ['newest', 'oldest']:
now = datetime.now(tz.tzutc())
sorted_items = sorted(sorted_items, key=lambda x:x.updated or x.time or now) # oldest to newest
if options.order == 'newest':
sorted_items = reversed(sorted_items)
for i, item in enumerate(sorted_items): for i, item in enumerate(sorted_items):
# hard cap # hard cap

View File

@ -204,7 +204,9 @@
link of the link of the
<select> <select>
<option value="">first</option> <option value="">first</option>
<option value=":newest" title="Select feed items by publication date (instead of appearing order)">newest (?)</option> <option value=":order=newest" title="Select feed items by publication date (instead of appearing order)">newest (?)</option>
<option value=":order=last">last</option>
<option value=":order=oldest">oldest</option>
</select> </select>
items and items and
<select> <select>