Skip to content

Instantly share code, notes, and snippets.

@wolkenarchitekt
Last active December 23, 2015 00:19
Show Gist options
  • Save wolkenarchitekt/6552475 to your computer and use it in GitHub Desktop.
Save wolkenarchitekt/6552475 to your computer and use it in GitHub Desktop.
Monitor IPython SQLite history; save into plain textfile on every update
#!/usr/bin/env bash
# Saves todays ipython history to textfile.
# Needs inotify-tools, sqlite3
HISTORY_SQLITE="${HOME}/.config/ipython/profile_default/history.sqlite"
HISTORY_FILE="${HOME}/.config/ipython/profile_default/history.py"
if [ ! -f "${HISTORY_FILE}" ]; then
touch "${HISTORY_FILE}"
fi
LAST_UPDATE="`date +%F` 00:00:00"
while true; do
inotifywait -e modify "${HISTORY_SQLITE}" &&
echo "
select distinct(source) from history, sessions
where history.session = sessions.session and sessions.start > '${LAST_UPDATE}'
order by sessions.start;" \
| sqlite3 "${HISTORY_SQLITE}" > "${HISTORY_FILE}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment