]> gitweb.pimeys.fr Git - scripts-20-100.git/blob - extract_ipython.py
Installer aussi tree et curl
[scripts-20-100.git] / extract_ipython.py
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
3
4 """ Pour récupérer le contenu de l'historique ipython """
5
6 import sqlite3
7 import os.path
8 import sys
9
10 if len(sys.argv) > 1:
11 n = int(sys.argv[1])
12 else:
13 n = 0
14
15 if n <= 0:
16 sessionid = "(SELECT max(session) FROM sessions) - %s" % (-n)
17 else:
18 sessionid = str(n)
19
20 req = 'SELECT * FROM history WHERE session=%s;' % sessionid
21
22 #print req
23
24 history_file = os.path.expanduser('~/.config/ipython/profile_default/history.sqlite')
25 if not os.path.isfile(history_file):
26 history_file = os.path.expanduser('~/.ipython/profile_default/history.sqlite')
27
28 c = sqlite3.connect(history_file)
29 r = c.execute(req)
30
31 for line in iter(r.fetchone, None):
32 print line[-1].encode('utf-8')