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 --- pyproject.toml | 2 ++ src/formbox.py | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d69bee3..b3a8166 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,11 @@ maintainers = [ { name = "Nguyễn Gia Phong", email = "mcsinyx@disroot.org" } ] keywords = [ "email", "format", "html", "mbox", "template", "xml" ] classifiers = [ "Development Status :: 4 - Beta", + "Environment :: Console", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python", + "Topic :: Communications :: Email", "Topic :: Utilities" ] dependencies = [ "bleach", "markdown" ] urls = { SourceHut = "https://sr.ht/~cnx/formbox" } 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