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 ...@@ -4,6 +4,13 @@ import json, sys
import os.path 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__': if __name__ == '__main__':
for lab_name in ('lab'+str(x) for x in xrange(7, start=1)): for lab_name in ('lab'+str(x) for x in xrange(7, start=1)):
...@@ -14,9 +21,8 @@ if __name__ == '__main__': ...@@ -14,9 +21,8 @@ if __name__ == '__main__':
print('Aborting, no src file') print('Aborting, no src file')
sys.exit() sys.exit()
with open('src/header.md') as fh, open('src/footer.md', 'rb') as ff: header_bin = readin('src/header.md')
header_bin = fh.read() footer_bin = readin('src/footer.md')
footer_bin = ff.read()
# Make directories # Make directories
try: try:
...@@ -25,15 +31,10 @@ if __name__ == '__main__': ...@@ -25,15 +31,10 @@ if __name__ == '__main__':
pass pass
# Load data # Load data
if os.path.exists('src/'+lab_name+'.json'): data = readin('src/'+lab_name+'.json', json.load, orelse=[{}])
with open('src/' + lab_name + '.json', 'rb') as datin:
data = json.load(datin)
else:
data = [{}]
# Load text # Load text
with open(src_md, 'rb') as labin: lab = readin(src_md, lambda x: x.decode('utf8'))
lab = labin.read().decode('utf8')
# Swap placholders # Swap placholders
for ex_no, d in enumerate(data, start=1): 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