-
Notifications
You must be signed in to change notification settings - Fork 6
log_notebook_activity
bchate edited this page Oct 23, 2018
·
3 revisions
This script shows how to implement printandlog function, using the notebook name as log name. To do to so it relies on a javascript file (described below) stored in ~/.jupyter/custom/custom.js and the following cell.
As the connection Python <-> javascript is quite bugged, the following script is a first attempt to intercept all potential situation... uncussesfully.
Here is the custom.js file:
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
// Create a nb_name variable with the name of the notebook
IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"');
});
Jupyter.notebook.events.one('kernel_restarting.Kernel', () => {
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
// Create a nb_name variable with the name of the notebook
IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"');
});
});
Jupyter.notebook.events.one('notebook_saved.Notebook', () => {
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
// Create a nb_name variable with the name of the notebook
IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"');
});
});
Jupyter.notebook.events.one('set_dirty.Notebook', () => {
// Create a nb_name variable with the name of the notebook
IPython.notebook.kernel.execute('nb_name = "' + IPython.notebook.notebook_name + '"');
});
Once the custom.js file created you need to restart Jupyter.
If you have credentials for the Swiss Data Cube, you can play with a demo script at
http://calc.unepgrid.ch:8080/notebooks/log_notebook_activity.ipynb
or
http://sdc.unepgrid.ch:8080/notebooks/log_notebook_activity.ipynb
The code and the demo jupyter notebook script can be found here