Created
March 23, 2013 15:46
-
-
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
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
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
This is so cool! 🤩
And so ahead of its time!!!