Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

process_nbs.py 1.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  1. import os
  2. import re
  3. from os.path import join as oj
  4. NOTEBOOKS_DIR = '../notebooks'
  5. OUTPUT_FILE = 'readme.md'
  6. ss = 'This is an overview of the markdown contents of all the notebooks / scripts in this directory.\n\n'
  7. for fname in sorted(os.listdir(NOTEBOOKS_DIR)):
  8. if fname.endswith('.md') and not fname == OUTPUT_FILE:
  9. with open(oj(NOTEBOOKS_DIR, fname), 'r') as f:
  10. s = f.read()
  11. s = re.sub("\```([^`]+)\```", '', s) # remove all code blocks
  12. s = re.sub("\---([^`]+)\---", '', s) # remove header
  13. s = s.replace('#### ', '##### ') # make all headers one header lower
  14. s = s.replace('### ', '#### ') # make all headers one header lower
  15. s = s.replace('## ', '### ') # make all headers one header lower
  16. s = s.replace('# ', '## ') # make all headers one header lower
  17. s = re.sub("((\r?\n|\r)\d*)+(\r?\n|\r)", '\n\n', s) # remove double newlines
  18. s = f'# {fname[:-3]}\n' + s
  19. ss += s
  20. os.remove(oj(NOTEBOOKS_DIR, fname))
  21. with open(oj(NOTEBOOKS_DIR, OUTPUT_FILE), 'w') as f:
  22. f.write(ss)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...