Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment