1
0

By month instead

This commit is contained in:
Jon Michael Aanes 2024-10-26 15:05:12 +02:00
parent fa50a6970a
commit 31bff7b639
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -8,12 +8,13 @@ from . import (format_messages, merge_adjacent_messages,
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def group_messages_by_year(messages: list[Message]) -> dict[int, list[Message]]: def group_messages_by_period(messages: list[Message]) -> dict[str, list[Message]]:
by_year = {} by_period: dict[str,list[Message]] = {}
for msg in messages: 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 del msg
return by_year return by_period
def parse_args(): def parse_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -34,15 +35,15 @@ def main():
all_messages = filter_useless_messages(all_messages) all_messages = filter_useless_messages(all_messages)
all_messages = merge_adjacent_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(): for period_key, messages in messages_by_period.items():
output_file = args.output / f'{server} - {receipient} - {year}.md' output_file = args.output / f'{server} - {receipient} - {period_key}.md'
logger.info("Writing %d messages to %s", len(messages), output_file) logger.info("Writing % 5d messages to %s", len(messages), output_file)
with open(output_file, 'w') as f: 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__': if __name__ == '__main__':