-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_code_html.py
More file actions
40 lines (29 loc) · 1010 Bytes
/
create_code_html.py
File metadata and controls
40 lines (29 loc) · 1010 Bytes
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
import os
def create_block(path, name):
res = ''
filename = os.path.join(path, name+".py")
if not os.path.exists(filename):
return res
with open(filename) as f:
res += '<code data-type="' + name +'">' + os.linesep
res += f.read()
res += '</code>' + os.linesep
return res
def create(head, example, tail):
path = os.path.join('code', example)
res = head
# working on sample code
res += '<code data-type="sample-code">' + os.linesep
with open(os.path.join(path, 'sample.py')) as f:
res += f.read()
res += '</code>' + os.linesep
res += create_block(path, "solution")
res += create_block(path, "sct")
res += create_block(path, "hint")
return res + tail
with open('head.html') as f: head = f.read()
with open('tail.html') as f: tail = f.read()
for example in os.listdir('code/'):
res = create(head, example, tail)
with open(os.path.join('docs', example + ".html"), "w") as f:
f.write(res)