Ruff
This commit is contained in:
parent
6f22e8d239
commit
634bd5b03f
|
@ -1,9 +1,8 @@
|
|||
import argparse
|
||||
import dataclasses
|
||||
import logging
|
||||
import datetime
|
||||
from collections.abc import Iterable, Iterator, Mapping
|
||||
from typing import Callable
|
||||
import logging
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping
|
||||
from pathlib import Path
|
||||
|
||||
from . import (
|
||||
|
@ -18,7 +17,10 @@ from .markdown import format_messages
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def group_messages(messages: Iterable[Message], key_fn: Callable[[Message], str]) -> dict[str, list[Message]]:
|
||||
def group_messages(
|
||||
messages: Iterable[Message],
|
||||
key_fn: Callable[[Message], str],
|
||||
) -> dict[str, list[Message]]:
|
||||
by_key: dict[str, list[Message]] = {}
|
||||
for msg in messages:
|
||||
by_key.setdefault(key_fn(msg), []).append(msg)
|
||||
|
@ -55,9 +57,14 @@ PERIOD_KEYS_BY_NAME: Mapping[str, Callable[[Message], str]] = {
|
|||
}
|
||||
|
||||
|
||||
def group_messages_by_period(messages: Iterable[Message], period_key: str | None = None) -> tuple[dict[str, list[Message]], Callable[[Message], str]]:
|
||||
def group_messages_by_period(
|
||||
messages: Iterable[Message],
|
||||
period_key: str | None = None,
|
||||
) -> tuple[dict[str, list[Message]], Callable[[Message], str]]:
|
||||
# Determine key function
|
||||
possible_period_keys: Iterable[Callable[[Message], str]] = PERIOD_KEYS_BY_NAME.values()
|
||||
possible_period_keys: Iterable[Callable[[Message], str]] = (
|
||||
PERIOD_KEYS_BY_NAME.values()
|
||||
)
|
||||
if period_key is not None:
|
||||
possible_period_keys = [PERIOD_KEYS_BY_NAME[period_key]]
|
||||
del period_key
|
||||
|
@ -89,10 +96,19 @@ def parse_args():
|
|||
parser.add_argument('--output', type=Path)
|
||||
parser.add_argument('--myself', type=str, default='Myself')
|
||||
parser.add_argument('--overwrite', action='store_true', dest='overwrite_files')
|
||||
parser.add_argument('--period', dest='period_key', choices=list(PERIOD_KEYS_BY_NAME.keys()))
|
||||
parser.add_argument('--skip-this-period', action='store_true', dest='skip_this_period')
|
||||
parser.add_argument(
|
||||
'--period',
|
||||
dest='period_key',
|
||||
choices=list(PERIOD_KEYS_BY_NAME.keys()),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--skip-this-period',
|
||||
action='store_true',
|
||||
dest='skip_this_period',
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig()
|
||||
logging.getLogger().setLevel('INFO')
|
||||
|
@ -125,7 +141,10 @@ def main():
|
|||
logger.info(' "%s": Skipped due to too few messages', chat_id)
|
||||
continue
|
||||
|
||||
messages_by_period, period_key_fn = group_messages_by_period(messages_in_chat, args.period_key)
|
||||
messages_by_period, period_key_fn = group_messages_by_period(
|
||||
messages_in_chat,
|
||||
args.period_key,
|
||||
)
|
||||
logger.info(
|
||||
' "%s": %d messages, %d periods (%d msg/period avg)',
|
||||
chat_id,
|
||||
|
@ -134,7 +153,7 @@ def main():
|
|||
len(messages_in_chat_original) / len(messages_by_period),
|
||||
)
|
||||
|
||||
this_period_name = period_key_fn(Message(datetime.datetime.now(), '','',''))
|
||||
this_period_name = period_key_fn(Message(datetime.datetime.now(), '', '', ''))
|
||||
|
||||
for period_key_name, messages in messages_by_period.items():
|
||||
file_escaped_chat_id = chat_id.replace(' ', '-')
|
||||
|
|
Loading…
Reference in New Issue
Block a user