diff options
author | mathieui <mathieui@mathieui.net> | 2021-04-10 22:52:01 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-04-11 16:33:53 +0200 |
commit | 91be567228046171aa12db04d77dcc9189ae57f9 (patch) | |
tree | ae9aec24e3e1701f211bc37bf64477f334872c9b | |
parent | bf8965fb4b6bb2c256e489069d1c2216e064b0ed (diff) | |
download | poezio-91be567228046171aa12db04d77dcc9189ae57f9.tar.gz poezio-91be567228046171aa12db04d77dcc9189ae57f9.tar.bz2 poezio-91be567228046171aa12db04d77dcc9189ae57f9.tar.xz poezio-91be567228046171aa12db04d77dcc9189ae57f9.zip |
feature: add a function to retrieve the last message from the logs
-rw-r--r-- | poezio/logger.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/poezio/logger.py b/poezio/logger.py index b7fe83c8..7b6a5dc5 100644 --- a/poezio/logger.py +++ b/poezio/logger.py @@ -334,6 +334,19 @@ def build_log_message(nick: str, return logged_msg + ''.join(' %s\n' % line for line in lines) +def last_message_in_archive(filepath: Path) -> Optional[Dict]: + """Get the last message from the local archive. + + :param filepath: the log file path + """ + last_msg = None + for msg in iterate_messages_reverse(filepath): + if msg['type'] == 'message': + last_msg = msg + break + return last_msg + + def iterate_messages_reverse(filepath: Path): """Get the latest messages from the log file, one at a time. |