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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
# Directories and files to ignore
|
| 5 |
+
IGNORE_DIRS = {".git", ".github"}
|
| 6 |
+
IGNORE_FILES = {"Dockerfile", "Cloner.py"}
|
| 7 |
+
|
| 8 |
+
# Folders to process
|
| 9 |
+
TARGET_FOLDERS = {"plugins", "data"}
|
| 10 |
+
|
| 11 |
+
# Text replacements
|
| 12 |
+
REPLACEMENTS = {
|
| 13 |
+
"Mr Frank": "DUDAS",
|
| 14 |
+
"SUBZERO-MD": "ENCRYPTO-27",
|
| 15 |
+
"SubZero MD": "ENCRYPTO-27",
|
| 16 |
+
"Subzero": "ENCRYPTO-27",
|
| 17 |
+
"Darrell Mucheri": "Diego Allies",
|
| 18 |
+
"18062212660": "27679291800",
|
| 19 |
+
"263719647303": "27679291800",
|
| 20 |
+
"https://github.com/mrfrank-ofc/SUBZERO-MD": "https://i.ibb.co/hx0rGm5/Encrypto.webp",
|
| 21 |
+
"https://whatsapp.com/channel/0029VagQEmB002T7MWo3Sj1D": "https://i.ibb.co/hx0rGm5/Encrypto.webp",
|
| 22 |
+
"https://chat.whatsapp.com/InsR5qk3cBsG2781A6uxcO": "https://i.ibb.co/hx0rGm5/Encrypto.webp",
|
| 23 |
+
"SUBZERO - MD- BOT": "ENCRYPTO-MD-BOT",
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# Metadata block to prepend to README.md
|
| 27 |
+
README_METADATA = """---
|
| 28 |
+
license: apache-2.0
|
| 29 |
+
title: ENCRYPTO MD
|
| 30 |
+
sdk: docker
|
| 31 |
+
emoji: 🚀
|
| 32 |
+
colorFrom: blue
|
| 33 |
+
colorTo: blue
|
| 34 |
+
short_description: The Best W.A bo
|
| 35 |
+
---
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
# Dockerfile content
|
| 39 |
+
DOCKERFILE_CONTENT = """
|
| 40 |
+
FROM node:lts-buster
|
| 41 |
+
|
| 42 |
+
# Install Git and other dependencies
|
| 43 |
+
RUN apt-get update && \\
|
| 44 |
+
apt-get install -y \\
|
| 45 |
+
git \\
|
| 46 |
+
ffmpeg \\
|
| 47 |
+
imagemagick \\
|
| 48 |
+
webp && \\
|
| 49 |
+
apt-get upgrade -y && \\
|
| 50 |
+
rm -rf /var/lib/apt/lists/*
|
| 51 |
+
|
| 52 |
+
# Copy package.json and install dependencies
|
| 53 |
+
COPY package.json .
|
| 54 |
+
RUN npm install && npm install -g qrcode-terminal pm2
|
| 55 |
+
|
| 56 |
+
# Copy application code
|
| 57 |
+
COPY . .
|
| 58 |
+
|
| 59 |
+
# Expose port and set command
|
| 60 |
+
EXPOSE 3000
|
| 61 |
+
CMD ["pm2-runtime", "start", "index.js"]
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
# Function to log messages to a text file
|
| 65 |
+
def log_to_file(log_message, log_file_path='logfile.txt'):
|
| 66 |
+
"""Function to log messages to a text file."""
|
| 67 |
+
with open(log_file_path, 'a') as log_file:
|
| 68 |
+
log_file.write(log_message + '\n')
|
| 69 |
+
|
| 70 |
+
def process_file(file_path):
|
| 71 |
+
"""Process a single file to replace text."""
|
| 72 |
+
try:
|
| 73 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 74 |
+
content = f.read()
|
| 75 |
+
|
| 76 |
+
original_content = content
|
| 77 |
+
for old, new in REPLACEMENTS.items():
|
| 78 |
+
content = re.sub(re.escape(old), new, content)
|
| 79 |
+
|
| 80 |
+
if content != original_content:
|
| 81 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 82 |
+
f.write(content)
|
| 83 |
+
log_to_file(f'Replaced text in {file_path}')
|
| 84 |
+
return True
|
| 85 |
+
else:
|
| 86 |
+
log_to_file(f'No changes made to {file_path}')
|
| 87 |
+
return False
|
| 88 |
+
|
| 89 |
+
except Exception as e:
|
| 90 |
+
log_to_file(f"Failed to process {file_path}: {e}")
|
| 91 |
+
return False
|
| 92 |
+
return False
|
| 93 |
+
|
| 94 |
+
def process_directory(directory):
|
| 95 |
+
"""Recursively process files in a directory."""
|
| 96 |
+
total_files = 0
|
| 97 |
+
successful_replacements = 0
|
| 98 |
+
|
| 99 |
+
for root, dirs, files in os.walk(directory):
|
| 100 |
+
# Ignore specified directories
|
| 101 |
+
dirs[:] = [d for d in dirs if d not in IGNORE_DIRS]
|
| 102 |
+
|
| 103 |
+
# Only process files in the target folders
|
| 104 |
+
if any(target_folder in root for target_folder in TARGET_FOLDERS):
|
| 105 |
+
for file in files:
|
| 106 |
+
if file in IGNORE_FILES:
|
| 107 |
+
continue
|
| 108 |
+
|
| 109 |
+
file_path = os.path.join(root, file)
|
| 110 |
+
total_files += 1
|
| 111 |
+
if process_file(file_path):
|
| 112 |
+
successful_replacements += 1
|
| 113 |
+
|
| 114 |
+
return total_files, successful_replacements
|
| 115 |
+
|
| 116 |
+
def update_readme(directory):
|
| 117 |
+
"""Add metadata to README.md in the root directory."""
|
| 118 |
+
readme_path = os.path.join(directory, "README.md")
|
| 119 |
+
try:
|
| 120 |
+
if os.path.exists(readme_path):
|
| 121 |
+
with open(readme_path, "r+", encoding="utf-8") as f:
|
| 122 |
+
content = f.read()
|
| 123 |
+
f.seek(0, 0)
|
| 124 |
+
f.write(README_METADATA + "\n" + content)
|
| 125 |
+
log_to_file(f'Updated README.md at {readme_path}')
|
| 126 |
+
else:
|
| 127 |
+
with open(readme_path, "w", encoding="utf-8") as f:
|
| 128 |
+
f.write(README_METADATA)
|
| 129 |
+
log_to_file(f'Created and added metadata to README.md at {readme_path}')
|
| 130 |
+
except Exception as e:
|
| 131 |
+
log_to_file(f"Failed to update README.md: {e}")
|
| 132 |
+
|
| 133 |
+
def create_dockerfile(dockerfile_path='Dockerfile'):
|
| 134 |
+
"""Function to create or replace the Dockerfile with the given content."""
|
| 135 |
+
try:
|
| 136 |
+
with open(dockerfile_path, 'w') as dockerfile:
|
| 137 |
+
dockerfile.write(DOCKERFILE_CONTENT)
|
| 138 |
+
log_to_file(f'Dockerfile has been created/updated at {dockerfile_path}.')
|
| 139 |
+
except Exception as e:
|
| 140 |
+
log_to_file(f"Failed to create/update Dockerfile: {e}")
|
| 141 |
+
|
| 142 |
+
if __name__ == "__main__":
|
| 143 |
+
repo_dir = os.getcwd() # Root directory of the repository
|
| 144 |
+
log_to_file('Script started.')
|
| 145 |
+
|
| 146 |
+
print("Starting bulk text replacement...")
|
| 147 |
+
|
| 148 |
+
total_files, successful_replacements = process_directory(repo_dir)
|
| 149 |
+
update_readme(repo_dir)
|
| 150 |
+
create_dockerfile()
|
| 151 |
+
|
| 152 |
+
log_to_file('Script completed successfully.')
|
| 153 |
+
|
| 154 |
+
print("\nBulk task completed!")
|
| 155 |
+
print(f"Total files processed: {total_files}")
|
| 156 |
+
print(f"Successful replacements: {successful_replacements}")
|
| 157 |
+
|
| 158 |
+
log_to_file(f"Total files processed: {total_files}")
|
| 159 |
+
log_to_file(f"Successful replacements: {successful_replacements}")
|