From 31bff7b63996cd32914ee09e92da8c860a63c5e9 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sat, 26 Oct 2024 15:05:12 +0200 Subject: [PATCH] By month instead --- libpurple_to_markdown/__main__.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libpurple_to_markdown/__main__.py b/libpurple_to_markdown/__main__.py index 79079b7..a060e5d 100644 --- a/libpurple_to_markdown/__main__.py +++ b/libpurple_to_markdown/__main__.py @@ -8,12 +8,13 @@ from . import (format_messages, merge_adjacent_messages, logger = logging.getLogger(__name__) -def group_messages_by_year(messages: list[Message]) -> dict[int, list[Message]]: - by_year = {} +def group_messages_by_period(messages: list[Message]) -> dict[str, list[Message]]: + by_period: dict[str,list[Message]] = {} for msg in messages: - by_year.setdefault(msg.sent_at.year, []).append(msg) + period_key = f'{msg.sent_at.year}-{msg.sent_at.month:02}' + by_period.setdefault(period_key, []).append(msg) del msg - return by_year + return by_period def parse_args(): parser = argparse.ArgumentParser() @@ -34,15 +35,15 @@ def main(): all_messages = filter_useless_messages(all_messages) all_messages = merge_adjacent_messages(all_messages) - messages_by_year = group_messages_by_year(all_messages) + messages_by_period = group_messages_by_period(all_messages) - for year, messages in messages_by_year.items(): - output_file = args.output / f'{server} - {receipient} - {year}.md' - logger.info("Writing %d messages to %s", len(messages), output_file) + for period_key, messages in messages_by_period.items(): + output_file = args.output / f'{server} - {receipient} - {period_key}.md' + logger.info("Writing % 5d messages to %s", len(messages), output_file) with open(output_file, 'w') as f: - f.write(format_messages(messages, title = f'{server} - {receipient} - {year}')) + f.write(format_messages(messages, title = f'{server} - {receipient} - {period_key}')) - del year, messages, output_file + del period_key, messages, output_file if __name__ == '__main__':