Skip to content

Instantly share code, notes, and snippets.

@Glench
Created March 23, 2013 15:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glench/5228158 to your computer and use it in GitHub Desktop.
Save Glench/5228158 to your computer and use it in GitHub Desktop.
a python script that watches the current directory for changes to ipython notebooks, compiles them to html, and uploads them via scp to a server. an experiment in real-time coding for teaching python to new programmers
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import envoy
import os
import datetime
class NotebookConverterHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path.endswith('.ipynb'):
# convert to html file
envoy.run('python nbconvert/nbconvert.py --format=html {}'.format(event.src_path))
# convert old file name with ipynb extension to html extension
new_file_name = os.path.splitext(os.path.split(event.src_path)[1])[0] + '.html'
# upload to my site
envoy.run('scp {} name@myawesomeserver'.format(new_file_name))
print 'uploaded {}'.format(datetime.datetime.now())
if __name__ == "__main__":
observer = Observer()
observer.schedule(NotebookConverterHandler(), path='.')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
@jlumbroso
Copy link

This is so cool! 🤩

And so ahead of its time!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment