Friday, August 06, 2010

Empathy log

source: http://home-gym-fitness-equipment.co.uk/files/log-book.jpg


This is the second lucky month that the Empathy icon lies on the top gnome-panel of my desktop. Well it is... let's say ok when compared with Pidgin. I love see Empathy developers add the buddy pounce function too. It was after the fresh F13 installation that I tried to give Empathy a try. It was pre-packaged with the the system (formerly it was Pidgin) and most importantly Open Source is all about Choice.

Empathy, as Pidgin does keeps a log of all the conversations we had via Empathy. Yeah, this can be deactivated also. The chat files of Empathy resides in ~/.local/share/Empathy/logs and I found them to be a little messy. They include all the technical data and other stuff and it makes us hard to find the messages. So I though to get it to a more human friendly and readable format and wrote the following python code. This for me works fine, and if there are any bugs, suggestions to improve, please leave a comment.

#!/usr/bin/python2.6
#
# W.H. Kalpa Pathum <callkalpa@gmail.com>
# 6th August, 2010
#
#    empathy_log.py
# This script formats a empathy log file in a more human readable way
# usage : empathy_log <empathy log file>
#

import re
import sys

msg_d = ''

def print_output(message_data):
    global msg_d
    
    # print the conversation date
    if msg_d != message_data[0]:
        msg_d = message_data[0]
        print 'Conversation with', message_data[2], 'on', msg_d

    print '('+ message_data[1]+ ')',  message_data[2], ':',  message_data[3]

def main(filename):
    f = open(filename, 'r')
    # read line by line and extract message details
    lines = f.readlines()

    for line in lines[3:-1]: # except first three lines and last line
        match = re.findall('^<message time=\'(\d+)T([\d:]+)\' [\w\W]+ name=\'([\w\W]+)\' token=[\w\W]+>([\w\W]+)<', line)
        if match:

            for item in match:
                # format msg_d
                d=item[0][:4] + '-' + item[0][4:6] + '-' + item[0][6:]
           
                message_data = [d, item[1], item[2], item[3]]
                print_output(message_data)
       
        # if the pattern is not found, print the modified line
        else:
            print re.sub('<[/message][\w\W]*>', '', line),

    f.close()

if __name__ == '__main__':
    main(sys.argv[1]) 


DOWNLOAD

3 comments:

  1. Or, you could just use the Empathy log viewer :)

    ReplyDelete
  2. This was useful to me, as I wanted to print one of my logs. thanks.

    ReplyDelete