Sample script: Messing around with chat history database
Attention: This script is unmaintained and intended for Gajim <1.0.
Here is a sample script to assist tail, grep. etc. lovers:
import pysqlite2.dbapi2 as sqlite import os db = os.path.expanduser('~/.local/share/gajim/logs.db') con = sqlite.connect(db) cur = con.cursor() jid = 'firstname.lastname@example.org' def get_jid_id(jid): '''jids table has jid and jid_id logs table has log_id, jid_id, contact_name, time, kind, show, message so to ask logs we need jid_id that matches our jid in jids table this method asks jid and returns the jid_id for later sql-ing on logs ''' cur.execute('SELECT jid_id FROM jids WHERE jid="%s"' %jid) jid_id = cur.fetchone() return jid_id jid_id = get_jid_id(jid) cur.execute('SELECT message from logs WHERE jid_id = %d' % jid_id) results = cur.fetchall() for res in results: print res
For time it needs special care since it's seconds since EPOCH. Here is an example of printing out status messages with date and time (import time):
cur.execute('SELECT time, show, message from logs WHERE jid_id = %d' % jid_id) results = cur.fetchall() for res in results: if res is not None: # Display only status messages. local_time = time.localtime(res) tim = time.strftime('%F %X', local_time) print tim, "%-8s" % (res,), res