-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.py
63 lines (48 loc) · 1.75 KB
/
create.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import json
from glob import glob
import os
import shutil
import nbformat
from nbconvert import HTMLExporter
from nbconvert.writers import FilesWriter
NOTEBOOK_FOLDERS_PATTERN = './src/content/pidgraph-notebooks-python/user-story*'
NOTEBOOK_SUFFIX_PATTERN = '*-inline.ipynb'
folders = glob(NOTEBOOK_FOLDERS_PATTERN)
for folder in folders:
# print(f'Extracting folder {folder}...')
nb = glob(folder+"/"+NOTEBOOK_SUFFIX_PATTERN)[0]
with open(nb) as nb_json:
nb_node = nbformat.read(nb_json, as_version=4)
# export html
exporter = HTMLExporter()
body, resources = exporter.from_notebook_node(nb_node)
# save html
writer = FilesWriter()
writer.write(output=body,
resources=resources,
notebook_name=nb)
print('-- Notebook extracted.', nb)
source = './src/content'
destination = './static/content'
shutil.copytree(source,destination)
# import json
# from glob import glob
# from pathlib import Path
# import nbformat
# from nbconvert import HTMLExporter
# from nbconvert.writers import FilesWriter
# NOTEBOOK_FOLDERS_PATTERN = '/Users/iliaskoutsakis/projects/pidgraph-notebooks-python/'
# NOTEBOOK_SUFFIX_PATTERN = '*.ipynb'
# for path in Path(NOTEBOOK_FOLDERS_PATTERN).rglob(NOTEBOOK_SUFFIX_PATTERN):
# print(f'Extracting folder {path.absolute()}...')
# with open(path) as nb_json:
# nb_node = nbformat.read(nb_json, as_version=4)
# # export html
# exporter = HTMLExporter()
# body, resources = exporter.from_notebook_node(nb_node)
# # save html
# writer = FilesWriter()
# writer.write(output=body,
# resources=resources,
# notebook_name=str(path))
# print(f'-- Notebook {path} extracted.')