Created
August 23, 2017 12:31
-
-
Save ceshine/2a68a96e7a9f72551d00c5578249340f to your computer and use it in GitHub Desktop.
Jupyter Notebook Post-save Hook: Auto-convert a Python script and a HTML from the notebook
This file contains hidden or 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
# Reference: https://svds.com/jupyter-notebook-best-practices-for-data-science/ | |
import os | |
from subprocess import check_call | |
def post_save(model, os_path, contents_manager): | |
"""post-save hook for converting notebooks to .py scripts""" | |
if model['type'] != 'notebook': | |
return # only do this for notebooks | |
d, fname = os.path.split(os_path) | |
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d) | |
check_call(['jupyter', 'nbconvert', '--to', 'html', fname], cwd=d) | |
c.FileContentsManager.post_save_hook = post_save |
Sorry. I'm not familiar with S3ContentsManager. Maybe you can check if it implements post_save_hook
first. If it does, the next step is to find a way to sync local files generated by jupyter nbconvert
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my content manager is S3ContentsManager. I basically source notebooks from S3 Folder. I tried to use this code in this form as well as replacing FileContentsManager in last line by S3ContentsManager., but it did not work for me. How will this code change for me?