-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_readme.py
More file actions
35 lines (31 loc) · 1.15 KB
/
update_readme.py
File metadata and controls
35 lines (31 loc) · 1.15 KB
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
import os
def detect_languages():
languages = set()
for root, _, files in os.walk('.'):
for file in files:
if file.endswith('.py'):
languages.add('Python')
elif file.endswith('.js'):
languages.add('JavaScript')
# Add more file extensions and corresponding languages as needed
return languages
def update_readme(languages):
readme_path = 'README.md'
with open(readme_path, 'r') as file:
lines = file.readlines()
with open(readme_path, 'w') as file:
in_languages_section = False
for line in lines:
if line.startswith('## Languages Used'):
in_languages_section = True
file.write('## Languages Used\n')
for language in languages:
file.write(f'- {language}\n')
elif in_languages_section and line.startswith('## '):
in_languages_section = False
file.write(line)
elif not in_languages_section:
file.write(line)
if __name__ == '__main__':
languages = detect_languages()
update_readme(languages)