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__':