@@ -0,0 +1,1119 @@
+#!/usr/bin/env python%0A%22%22%22Extract a session from the IPython input history.%0A%0AUsage:%0A  ipython-get-history.py sessionnumber %5Boutputfile%5D%0A%0AIf outputfile is not given, the relevant history is written to stdout. If%0Aoutputfile has a .py extension, the translated history (without IPython's%0Aspecial syntax) will be extracted.%0A%0AExample:%0A  ./ipython-get-history.py 57 record.ipy%0A%0A%0AThis script is a simple demonstration of HistoryAccessor. It should be possible%0Ato build much more flexible and powerful tools to browse and pull from the%0Ahistory database.%0A%22%22%22%0Aimport sys%0Aimport codecs%0A%0Afrom IPython.core.history import HistoryAccessor%0A%0Asession_number = int(sys.argv%5B1%5D)%0Aif len(sys.argv) %3E 2:%0A    dest = open(sys.argv%5B2%5D, %22w%22)%0A    raw = not sys.argv%5B2%5D.endswith('.py')%0Aelse:%0A    dest = sys.stdout%0A    raw = True%0Adest.write(%22# coding: utf-8%5Cn%22)%0A%0A# Profiles other than 'default' can be specified here with a profile= argument:%0Ahist = HistoryAccessor()%0A%0Afor session, lineno, cell in hist.get_range(session=session_number, raw=raw):%0A    # To use this in Python 3, remove the .encode() here:%0A    dest.write(cell.encode('utf-8') + '%5Cn')%0A

Add example script for extracting history from the database.