diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2022-01-10 20:55:17 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2022-01-11 21:57:29 +0700 |
commit | 03c249a5326f412dc63b4f5a5465ea80fd822dda (patch) | |
tree | 8656500a81a2a8614728d3bbfbc774bb62c5590d /src | |
parent | 52541db07e34db6507416537150e4250b0617d5f (diff) | |
download | formbox-03c249a5326f412dc63b4f5a5465ea80fd822dda.tar.gz |
Minimize sorting
Diffstat (limited to 'src')
-rw-r--r-- | src/formbox.py | 9 |
1 files changed, 4 insertions, 5 deletions
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='') |