forked from barbagroup/CFDPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-readme.py
49 lines (34 loc) · 1.11 KB
/
gen-readme.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
#Original code written by https://bitbucket.org/hrojas/learn-pandas/
from glob import glob
from urllib.parse import quote
import re
header = '''
Welcome to the CFD Online Lesson Repository
Lessons
-------
'''
format_item = '* [{name}]({url})'.format
bb_url = 'github.com/barbagroup/CFDPython/blob/master/{}'.format
def notebooks():
return glob('lessons/*.ipynb')
def lesson_id(filename):
return int(re.search('[0-9]+', filename).group())
def lesson_name(filename):
filename = filename.split('/')[1].split('.')[0]
return filename[filename.find('_')+1:].replace('_',' ')
def nb_url(filename):
raw_url = bb_url(quote(quote(filename)))
return 'http://nbviewer.ipython.org/urls/{}'.format(raw_url)
def write_readme(nblist, fo):
fo.write('{}\n'.format(header))
for nb in nblist:
name = lesson_name(nb)
url = nb_url(nb)
fo.write('{}\n'.format(format_item(name=name, url=url)))
def main():
nblist = sorted(notebooks(), key=lesson_id)
with open('README.md', 'w') as fo:
write_readme(nblist, fo)
if __name__ == '__main__':
main()