From 1ebfd0944a0773420c782088c398932f3c0b209a Mon Sep 17 00:00:00 2001 From: juk0de Date: Fri, 29 Sep 2023 06:59:46 +0200 Subject: [PATCH] hist_cmd: startet to implement '--convert' --- chatmastermind/commands/hist.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/chatmastermind/commands/hist.py b/chatmastermind/commands/hist.py index 5b14bd2..09cf0ce 100644 --- a/chatmastermind/commands/hist.py +++ b/chatmastermind/commands/hist.py @@ -2,7 +2,26 @@ import argparse from pathlib import Path from ..configuration import Config from ..chat import ChatDB -from ..message import MessageFilter +from ..message import MessageFilter, Message + + +msg_suffix = Message.file_suffix_write + + +def convert(args: argparse.Namespace, config: Config) -> None: + """ + Convert messages to a new format. Also used to change the suffix, + to the latest default message file suffix. + """ + chat = ChatDB.from_dir(Path(config.cache), + Path(config.db)) + # read all known message files + msgs = chat.msg_gather(loc='disk', glob='*.*') + # make a set of all message IDs + # msg_ids = set([m.msg_id() for m in msgs]) + # set requested format and write all messages + chat.set_msg_format(args.format) + chat.msg_write(msgs) def hist_cmd(args: argparse.Namespace, config: Config) -> None: