Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Created November 22, 2023 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Edwardtonnn/b06b339b3dedb2233afc29b05cd41978 to your computer and use it in GitHub Desktop.
Save Edwardtonnn/b06b339b3dedb2233afc29b05cd41978 to your computer and use it in GitHub Desktop.
To lowercase all lazy-src=""
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