Skip to content

Commit

Permalink
Script now create yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
SrNetoChan committed Aug 9, 2017
1 parent 1aa0353 commit 4d86684
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions split_full_lesson.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re
import sys

import yaml

def main ():

Expand All @@ -10,39 +10,59 @@ def main ():
folder = os.path.dirname(fl_path)
s_file = None
s_list= []
l_structure = {'name': '',
'group': '',
'description': 'lesson.html',
'steps': [],
'nextLessons': [{'name': '', 'group': ''}]}
s_number = 0
with open(fl_path) as full_lesson:
for line in full_lesson:

# Patterns
l = re.match('#\s(.*)', line) # lesson title pattern
s = re.match('##\s(.*)', line) # step title pattern
b = re.match('\n', line) # step title pattern

if l:
l_title = (l.group(0))[2:]
next(full_lesson) #skip empty line after heading
pline_header = True
l_structure['name'] = l_title

# Get step title from markdown heading 2
elif s:
s_number += 1
s_title = (s.group(0))[3:]
s_file_name = '{0:02d}'.format(s_number) + '_' + \
s_title.replace(' ', '_').lower() + '.md'
s_file_name = '{0:02d}_{1}.md'.format(s_number, s_title.replace(
' ', '_').lower())
l_structure['steps'].append({'name':l_title,
'description': s_file_name})
s_list.append((s_title, s_file_name))

# Close description file from previous step
if s_file != None:
s_file.close()

# Open step description file
s_file = open(os.path.join(folder, s_file_name), 'w')
pline_header = True


# Get step description
# Skip blanklines
elif b and pline_header:
pline_header = True
else:
s_file.write(line)
#Write to opened file
s_file.write(line) #Write to opened file
pline_header = False

s_file.close()

# Write Lesson's YAML file
with open(os.path.join(folder, 'lesson.yaml'), 'w') as yaml_file:
yaml.dump(l_structure, yaml_file, default_flow_style=False,
allow_unicode=True)
print "Splitting was completed."

if __name__ == '__main__':
main()
main()

0 comments on commit 4d86684

Please sign in to comment.