--- /dev/null
+#!/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')