toolkit / cringe_move_exaple_images.py
k4d3's picture
lotta changes
ba7d855
raw
history blame
1.21 kB
import os
import re
def move_example_images_section(file_path):
with open(file_path, 'r') as file:
content = file.read()
example_images_section = re.search(r'## Example Images.*?(?=##|$)', content, re.DOTALL)
introduction_index = content.find('## Introduction')
if example_images_section and introduction_index != -1:
example_images_text = example_images_section.group()
# Remove the "## Example Images" section from its original position
content = content.replace(example_images_text, '')
# Insert the "## Example Images" section above the "## Introduction" section
new_content = content[:introduction_index] + example_images_text + '\n' + content[introduction_index:]
with open(file_path, 'w') as file:
file.write(new_content)
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)
move_example_images_section(file_path)
if __name__ == '__main__':
target_directory = '.' # Default to current directory
recurse_directories(target_directory)