-
Notifications
You must be signed in to change notification settings - Fork 176
/
create_slides.py
34 lines (26 loc) · 1.09 KB
/
create_slides.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
import subprocess
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--file', dest='file_name', type=str, help='Name of the jupyter notebook.')
args = parser.parse_args()
def clean_html(html_file):
"""Remove unnecessary tags from slides."""
clean_file = (html_file.replace('<section><section><image>', '')
.replace('</image></section></section>', ''))
return clean_file
def main():
"""Convert the notebook to slides and then do some cleaning."""
try:
output = subprocess.check_output(
['jupyter', 'nbconvert', args.file_name, '--to', 'slides', '--reveal-prefix', 'reveal.js-3.1.0',
'--config', 'static/slides_config.py'], stderr=subprocess.STDOUT).decode('utf-8')
print(output.rstrip())
slide_name = output.split(' ')[-1].rstrip()
with open(slide_name, 'r') as f:
clean_file = clean_html(f.read())
with open(slide_name, 'w') as f:
f.write(clean_file)
print('Successfully adjusted.')
except IndexError:
print('Provide name of the slide.')
main()