Skip to content

Instantly share code, notes, and snippets.

@cowlicks
Last active December 26, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cowlicks/7077935 to your computer and use it in GitHub Desktop.
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.
#!/usr/bin/env python
"""A script to generate and serve the slides from a ipython notebook
that auto updates the slides. It would be nice to include something like
this in IPython. Usage:
>>> python serve_slides.py presentation.ipynb
"""
import sys
import subprocess
import pyinotify
infile = sys.argv[1]
# It would be better to use IPython's API but...
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