A little tool for exporting dino logs

Tags:tech

As dino doesn't support exporting chat logs in text, I built a little python script to do it by reading from the database. This is not doing good SQL, and it only works in MUCs. But it did the job for me and I want to share it. Too tiny for a project so here's the code!

import sqlite3
import os
import sys

p = os.path.join(os.environ["HOME"], ".local/share/dino/dino.db")
conn = sqlite3.connect(p)
c = conn.cursor()

# Unsafe but who cares
jids = conn.execute(f'SELECT id FROM jid WHERE bare_jid LIKE "%{sys.argv[1]}%"')
i = jids.fetchone()[0]
 
messages = conn.execute('SELECT counterpart_resource, our_resource, body FROM message WHERE counterpart_id=:id', {"id": i})

for m in messages:
	nick = ''
	if m[0] == None:
		nick = m[1]
	else:
		nick = m[0]
	print(f'<{nick}> {m[2]}')

go home