Created
November 22, 2023 15:04
-
-
Save Edwardtonnn/b06b339b3dedb2233afc29b05cd41978 to your computer and use it in GitHub Desktop.
To lowercase all lazy-src=""
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
# Function to lowercase everything within the 'lazy-src' attribute in an HTML file | |
def lowercase_lazy_src(file_path): | |
with open(file_path, 'r', encoding='utf-8') as file: | |
content = file.read() | |
# Use regular expression to find all 'lazy-src' attributes and lowercase their values | |
modified_content = re.sub(r'lazy-src="([^"]+)"', lambda match: f'lazy-src="{match.group(1).lower()}"', content, flags=re.IGNORECASE) | |
# Write the modified content back to the file | |
with open(file_path, 'w', encoding='utf-8') as file: | |
file.write(modified_content) | |
# Function to loop through all subdirectories and process index.php files | |
def process_subdirectories(base_dir): | |
for root, dirs, files in os.walk(base_dir): | |
for file in files: | |
if file == 'index.php': | |
file_path = os.path.join(root, file) | |
lowercase_lazy_src(file_path) | |
print(f"Processed: {file_path}") | |
# Specify the base directory where you want to start the search | |
base_directory = './' | |
# Call the function to process subdirectories | |
process_subdirectories(base_directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment