Skip to content
Snippets Groups Projects
Commit 2b41544c authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

cleanup

parent 7fd202a2
No related branches found
No related tags found
No related merge requests found
Pipeline #2373 failed with stage
in 11 seconds
......@@ -4,6 +4,13 @@ import json, sys
import os.path
def readin(path, func=lambda x: x, orelse=None):
if os.path.exists(path):
with open(path, 'rb') as fin:
return func(fin.read())
else:
return orelse
if __name__ == '__main__':
for lab_name in ('lab'+str(x) for x in xrange(7, start=1)):
......@@ -14,9 +21,8 @@ if __name__ == '__main__':
print('Aborting, no src file')
sys.exit()
with open('src/header.md') as fh, open('src/footer.md', 'rb') as ff:
header_bin = fh.read()
footer_bin = ff.read()
header_bin = readin('src/header.md')
footer_bin = readin('src/footer.md')
# Make directories
try:
......@@ -25,15 +31,10 @@ if __name__ == '__main__':
pass
# Load data
if os.path.exists('src/'+lab_name+'.json'):
with open('src/' + lab_name + '.json', 'rb') as datin:
data = json.load(datin)
else:
data = [{}]
data = readin('src/'+lab_name+'.json', json.load, orelse=[{}])
# Load text
with open(src_md, 'rb') as labin:
lab = labin.read().decode('utf8')
lab = readin(src_md, lambda x: x.decode('utf8'))
# Swap placholders
for ex_no, d in enumerate(data, start=1):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment