toolkit / move_example_section
k4d3's picture
lotta changes
ba7d855
raw
history blame
1.08 kB
import os
def add_example_images_section(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
introduction_index = None
for i, line in enumerate(lines):
if line.strip().startswith('## Introduction'):
introduction_index = i
break
if introduction_index is not None:
example_images_section = '## Example Images\n\n'
if example_images_section not in lines:
lines.insert(introduction_index, example_images_section)
with open(file_path, 'w') as file:
file.writelines(lines)
def recurse_directories(target_dir='.'):
for root, dirs, files in os.walk(target_dir):
for file in files:
if file.endswith('.md'):
file_path = os.path.join(root, file)
add_example_images_section(file_path)
if __name__ == '__main__':
target_directory = input('Enter the target directory (leave blank for current directory): ')
if not target_directory:
target_directory = '.'
recurse_directories(target_directory)