Skip to content

Instantly share code, notes, and snippets.

@damianavila
Forked from cowlicks/serve_slides.py
Created October 21, 2013 18:15
Show Gist options
  • Save damianavila/7088388 to your computer and use it in GitHub Desktop.
Save damianavila/7088388 to your computer and use it in GitHub Desktop.
#!/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