Last active
December 26, 2015 02:19
-
-
Save cowlicks/7077935 to your computer and use it in GitHub Desktop.
script to generate and serve slides from an ipython notebook, it regenerates the slides when they are changed.
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
| #!/usr/bin/env python | |
| """A script to generate and serve the slides from a ipython notebook | |
| that auto updates the slides. Usage: | |
| >>> python serve_slides.py presentation.ipynb | |
| """ | |
| import sys | |
| import subprocess | |
| import pyinotify | |
| infile = sys.argv[1] | |
| # A hack because nbconvert lacks documentation. | |
| serve = 'ipython nbconvert --to slides --post serve ' + infile | |
| export = 'ipython nbconvert --to slides ' + infile | |
| def onChange(ev): | |
| """Regenerate slides from the notebook.""" | |
| subprocess.call(export.split(' ')) | |
| # Setup pyinotify to watch the notebook. | |
| wm = pyinotify.WatchManager() | |
| wm.add_watch(infile, pyinotify.IN_MODIFY, onChange) | |
| notifier = pyinotify.Notifier(wm) | |
| # generate and serve the slides. | |
| serve = subprocess.Popen(serve.split(" ")) | |
| while True: | |
| try: | |
| # Start watching the notebook for changes. | |
| notifier.loop() | |
| except KeyboardInterrupt: | |
| # Clean up | |
| serve.kill() | |
| notifier.stop() | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment