From 03c249a5326f412dc63b4f5a5465ea80fd822dda Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 10 Jan 2022 20:55:17 +0700 Subject: Minimize sorting --- src/formbox.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/formbox.py b/src/formbox.py index 46bad22..776b3e0 100644 --- a/src/formbox.py +++ b/src/formbox.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # Format mbox as HTML/XML -# Copyright (C) 2021 Nguyễn Gia Phong +# Copyright (C) 2021-2022 Nguyễn Gia Phong # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published @@ -70,7 +70,7 @@ def date(message): def render(template, archive, parent): """Render the thread recursively based on given template.""" - for self in archive[parent]: + for self in sorted(archive[parent], key=date): body = get_body(self) if body is None: continue message_id = self['Message-Id'] @@ -88,14 +88,13 @@ def render(template, archive, parent): def main(): """Parse command-line arguments and pass them to routines.""" parser = ArgumentParser(description='format mbox as HTML/XML') - parser.add_argument('mbox', help='path to mbox file') + parser.add_argument('mbox', type=mbox, help='path to mbox file') parser.add_argument('id', type=unquote, help='root message ID') parser.add_argument('template', type=Path, help='path to template') args = parser.parse_args() archive = defaultdict(list) - for message in sorted(mbox(args.mbox), key=date): - archive[message['In-Reply-To']].append(message) + for message in args.mbox: archive[message['In-Reply-To']].append(message) template = args.template.read_text() print(*render(template, archive, args.id), sep='', end='') -- cgit 1.4.1