2024-07-15 11:23:08 +00:00
|
|
|
import re
|
2024-07-15 11:32:40 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
# Set the correct path to the README.md file
|
|
|
|
script_dir = os.path.dirname(__file__) # Get the directory where the script is located
|
|
|
|
root_dir = os.path.join(script_dir, '..') # Move up to the root directory
|
|
|
|
readme_path = os.path.join(root_dir, 'README.md') # Path to the README.md in the root
|
2024-07-15 11:23:08 +00:00
|
|
|
|
|
|
|
# Load the README file
|
2024-07-15 11:32:40 +00:00
|
|
|
with open(readme_path, 'r', encoding='utf-8') as file:
|
2024-07-15 11:23:08 +00:00
|
|
|
readme_contents = file.read()
|
|
|
|
|
|
|
|
# Count the list items
|
2024-07-15 11:32:40 +00:00
|
|
|
list_count = len(re.findall(r'^\s*-\s', readme_contents, re.MULTILINE))
|
2024-07-15 11:23:08 +00:00
|
|
|
|
|
|
|
# Define the new banner message
|
|
|
|
new_banner = f'## Current List Count: {list_count}'
|
|
|
|
|
|
|
|
# Replace old banner with new banner in README
|
|
|
|
new_readme_contents = re.sub(r'## Current List Count: \d+', new_banner, readme_contents)
|
|
|
|
|
|
|
|
# Save the changes back to README.md
|
2024-07-15 11:32:40 +00:00
|
|
|
with open(readme_path, 'w', encoding='utf-8') as file:
|
2024-07-15 11:23:08 +00:00
|
|
|
file.write(new_readme_contents)
|