Skip to content

Instantly share code, notes, and snippets.

@Hosuke
Last active July 15, 2023 19:08
Show Gist options
  • Save Hosuke/cd8f57cd3b82d13030ac311a684cae74 to your computer and use it in GitHub Desktop.
Save Hosuke/cd8f57cd3b82d13030ac311a684cae74 to your computer and use it in GitHub Desktop.
import os
import re
# Get the current directory
dir_path = os.getcwd()
# Traverse all files and subdirectories in the current directory
for root, dirs, files in os.walk(dir_path):
for file_name in files:
# Skip this file
if file_name.endswith('_legacy.sql'):
continue
with open(os.path.join(root, file_name), 'r') as f:
content = f.read()
# pattern to match 0x followed by 40 hex characters
pattern = r'\'0x[0-9a-fA-F]{40}\''
# replace all matches
updated_content = re.sub(pattern, lambda m: m.group().lower().replace('\'', ''), content)
if content != updated_content:
print('Updating file: {}'.format(os.path.join(root, file_name)))
with open(os.path.join(root, file_name), 'w') as f:
f.write(updated_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment