-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_readme.py
51 lines (34 loc) · 1.37 KB
/
update_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
50
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import os
def generate_directory_tree(path, indent=''):
tree = ''
items = sorted(os.listdir(path))
items = [item for item in items if item not in ['.DS_Store', '.git', '.ipynb_checkpoints']]
for i, item in enumerate(items):
item_path = os.path.join(path, item)
tree += f'{indent}├── {item}\n'
if os.path.isdir(item_path):
if i == len(items) - 1:
tree += generate_directory_tree(item_path, indent + ' ')
else:
tree += generate_directory_tree(item_path, indent + '│ ')
return tree
# path to root directory
root_directory = '.'
# directory tree
directory_tree = generate_directory_tree(root_directory)
print(directory_tree)
with open('README.md', 'r') as readme_file:
readme_content = readme_file.read()
# update in the README.md file, looks for ''' ''' section
start_tag = '```'
end_tag = '```'
start_index = readme_content.find(start_tag)
end_index = readme_content.find(end_tag, start_index + len(start_tag))
# update repostructure
updated_readme_content = readme_content[:start_index + len(start_tag)] + '\n' + directory_tree + readme_content[end_index:]
with open('README.md', 'w') as readme_file:
readme_file.write(updated_readme_content)
print('Directory structure in README.md updated successfully.')