From 0b16271a5e0c386578ece0ea6d8bcf3239b32a5e Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sat, 9 Nov 2013 01:56:39 +0100 Subject: [PATCH] Pour afficher l'historique d'une session ipython --- extract_ipython.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 extract_ipython.py 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') -- 2.39.2