-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgen_titles.py
35 lines (26 loc) · 833 Bytes
/
gen_titles.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
#!/usr/bin/env python3
import re
import os
files = []
for directory, _, filenames in os.walk('src'):
for filename in filenames:
files.append(os.path.join(directory, filename))
def sort_key(path):
return tuple(int(re.sub(r'[^0-9]', '', x) or 0) for x in path.split('/'))
files.sort(key=sort_key)
print('% Notions de Python avancées')
for filename in files:
with open(filename, 'r') as f:
code = False
for line in f:
if re.match(r'```', line):
code = not code
continue
if code:
continue
m = re.match(r'(#+) (.+)$', line)
if m:
tabs = len(m.group(1)) - 1
if not tabs:
print()
print('{}- {}'.format(' ' * tabs, m.group(2)))