-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathbs.py
39 lines (31 loc) · 1.22 KB
/
bs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import subprocess
import shutil
import sys
import time
reveal = ' --reveal-prefix="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0/" '
def convert(nb, tpl) :
nb_tpl = './%s.tpl' % nb
if os.path.isfile(nb_tpl) : #if customized template exists, uses it
tpl = nb_tpl
cmd = 'jupyter nbconvert --to slides --template ' + tpl + reveal
cmd += "{:s}.ipynb".format(nb)
print(cmd)
subprocess.call(cmd, shell=True)
def convertAllNb(tpl) :
return [convert(os.path.splitext(os.path.basename(f))[0], tpl)
for f in os.listdir(".") if f.endswith(".ipynb")]
def convertNewNb(tpl) :
for f in os.listdir(".") :
if f.endswith(".ipynb") :
nbt = os.path.getmtime(f)
htmlf = f.replace(".ipynb", ".slides.html")
hashtml = os.path.isfile(htmlf)
if (not hashtml) or os.path.getmtime(htmlf) < nbt :
convert(os.path.splitext(os.path.basename(f))[0], tpl)
if __name__ == "__main__" :
if len(sys.argv) > 1 :
convert(sys.argv[1], 'hidecode.tpl')
else: # convert all if nothing is supplied
convertNewNb("hidecode.tpl")
[shutil.copy(f, '../gh-pages') for f in os.listdir(".") if f.endswith(".html")]