import os
import re
# Regex to match any character outside the standard ASCII range (0-127)
ASCII_PATTERN = re.compile(r'[^\x00-\x7f]')
def purge_file(path):
try:
with open(path, 'r', encoding='utf-8') as f:
content = f.read()
if ASCII_PATTERN.search(content):
print(f"Purging emojis from {path}...")
# Use a space or strip them
new_content = ASCII_PATTERN.sub('', content)
with open(path, 'w', encoding='utf-8') as f:
f.write(new_content)
return True
except Exception as e:
print(f"Failed to process {path}: {e}")
return False
def main():
base_dir = "src/agent_node"
count = 0
for root, dirs, files in os.walk(base_dir):
for f in files:
if f.endswith('.py'):
full_path = os.path.join(root, f)
if purge_file(full_path):
count += 1
print(f"Total files purged: {count}")
if __name__ == "__main__":
main()