diff --git a/README.md b/README.md index 37cf248..8a663ce 100644 --- a/README.md +++ b/README.md @@ -392,10 +392,11 @@ The list of arguments can be obtained by running `morss --help` ``` usage: morss [-h] [--post STRING] [--xpath XPATH] [--format {rss,json,html,csv}] [--search STRING] [--clip] - [--indent] [--cache] [--force] [--proxy] [--newest] [--firstlink] - [--resolve] [--items XPATH] [--item_link XPATH] - [--item_title XPATH] [--item_content XPATH] [--item_time XPATH] - [--nolink] [--noref] [--silent] + [--indent] [--cache] [--force] [--proxy] + [--order {first,last,newest,oldest}] [--firstlink] [--resolve] + [--items XPATH] [--item_link XPATH] [--item_title XPATH] + [--item_content XPATH] [--item_time XPATH] [--nolink] [--noref] + [--silent] url Get full-text RSS feeds @@ -403,7 +404,7 @@ Get full-text RSS feeds positional arguments: url feed url -optional arguments: +options: -h, --help show this help message and exit --post STRING POST request --xpath XPATH xpath rule to manually detect the article @@ -422,8 +423,9 @@ action: articles' content), so as to save time --force force refetch the rss feed and articles --proxy doesn't fill the articles - --newest return the feed items in chronological order (morss - ohterwise shows the items by appearing order) + --order {first,last,newest,oldest} + order in which to process items (which are however NOT + sorted in the output) --firstlink pull the first article mentioned in the description instead of the default link --resolve replace tracking links with direct links to articles diff --git a/morss/morss.py b/morss/morss.py index 4c04243..bdb87ac 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -328,14 +328,20 @@ def FeedGather(rss, url, options): if options.cache: max_time = 0 - if options.newest: - # :newest take the newest items (instead of appearing order) - now = datetime.now(tz.tzutc()) - sorted_items = sorted(rss.items, key=lambda x:x.updated or x.time or now, reverse=True) + # sort + sorted_items = list(rss.items) - else: - # default behavior, take the first items (in appearing order) - sorted_items = list(rss.items) + if options.order == 'last': + # `first` does nothing from a practical standpoint, so only `last` needs + # 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): # hard cap diff --git a/www/sheet.xsl b/www/sheet.xsl index 69eb9f2..ab188fe 100644 --- a/www/sheet.xsl +++ b/www/sheet.xsl @@ -204,7 +204,9 @@ link of the items and