Here is a sample script to assist tail, grep etc lovers:
#! /usr/bin/env python
import pysqlite2.dbapi2 as sqlite
import os
db = os.path.expanduser('~/.gajim/logs.db')
con = sqlite.connect(db)
cur = con.cursor()
jid = 'gajim@conference.jabber.no'
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[1] is not None: # Display only status messages.
local_time = time.localtime(res[0])
tim = time.strftime('%F %X', local_time)
print tim, "%-8s" % (res[1],), res[2]
For more, read about the design of the database
