forked from barbagroup/AeroPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-readme.py
executable file
·48 lines (33 loc) · 1.4 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
#!/usr/bin/env python2
from glob import glob
from urllib import quote
import re
header = '''
## Aerodynamics-Hydrodynamics with Python
"Aerodynamics-Hydrodynamics" (MAE 6226) is taught at the George Washington University by Prof. Lorena Barba for the first time in Spring 2014. These IPython Notebooks are being prepared for this class, with assistance from Barba-group PhD student Olivier Mesnard.
The materials are distributed publicly and openly under a Creative Commons Attribution license, [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/)
### List of notebooks:
'''
format_item = '* [{name}]({url})'.format
bb_url = 'github.com/barbagroup/AeroPython/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):
return filename.split('/')[1].split('.')[0].split('_')[2]
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()