Last active
December 23, 2015 00:19
-
-
Save wolkenarchitekt/6552475 to your computer and use it in GitHub Desktop.
Monitor IPython SQLite history; save into plain textfile on every update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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