From: Vincent Le Gallic Date: Sat, 9 Nov 2013 00:56:39 +0000 (+0100) Subject: Pour afficher l'historique d'une session ipython X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=0b16271a5e0c386578ece0ea6d8bcf3239b32a5e;p=scripts-20-100.git Pour afficher l'historique d'une session ipython --- diff --git a/extract_ipython.py b/extract_ipython.py new file mode 100755 index 0000000..50cd04e --- /dev/null +++ b/extract_ipython.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +""" Pour récupérer le contenu de l'historique ipython """ + +import sqlite3 +import os.path +import sys + +if len(sys.argv) > 1: + n = int(sys.argv[1]) +else: + n = 0 + +if n <= 0: + sessionid = "(SELECT max(session) FROM sessions) - %s" % (-n) +else: + sessionid = str(n) + +req = 'SELECT * FROM history WHERE session=%s;' % sessionid + +#print req +history_file = os.path.expanduser('~/.ipython/profile_default/history.sqlite') + +c = sqlite3.connect(history_file) +r = c.execute(req) + +for line in iter(r.fetchone, None): + print line[-1].encode('utf-8')