File size: 5,068 Bytes
f53f8d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
import re

# Directories and files to ignore
IGNORE_DIRS = {".git", ".github"}
IGNORE_FILES = {"Dockerfile", "Cloner.py"}

# Folders to process
TARGET_FOLDERS = {"plugins", "data"}

# Text replacements
REPLACEMENTS = {
    "Mr Frank": "DUDAS",
    "SUBZERO-MD": "ENCRYPTO-27",
    "SubZero MD": "ENCRYPTO-27",
    "Subzero": "ENCRYPTO-27",
    "Darrell Mucheri": "Diego Allies",
    "18062212660": "27679291800",
    "263719647303": "27679291800",
    "https://github.com/mrfrank-ofc/SUBZERO-MD": "https://i.ibb.co/hx0rGm5/Encrypto.webp",
    "https://whatsapp.com/channel/0029VagQEmB002T7MWo3Sj1D": "https://i.ibb.co/hx0rGm5/Encrypto.webp",
    "https://chat.whatsapp.com/InsR5qk3cBsG2781A6uxcO": "https://i.ibb.co/hx0rGm5/Encrypto.webp",
    "SUBZERO - MD- BOT": "ENCRYPTO-MD-BOT",
}

# Metadata block to prepend to README.md
README_METADATA = """---
license: apache-2.0
title: ENCRYPTO MD
sdk: docker
emoji: 🚀
colorFrom: blue
colorTo: blue
short_description: The Best W.A bo
---
"""

# Dockerfile content
DOCKERFILE_CONTENT = """
FROM node:lts-buster

# Install Git and other dependencies
RUN apt-get update && \\
    apt-get install -y \\
    git \\
    ffmpeg \\
    imagemagick \\
    webp && \\
    apt-get upgrade -y && \\
    rm -rf /var/lib/apt/lists/*

# Copy package.json and install dependencies
COPY package.json .
RUN npm install && npm install -g qrcode-terminal pm2

# Copy application code
COPY . .

# Expose port and set command
EXPOSE 3000
CMD ["pm2-runtime", "start", "index.js"]
"""

# Function to log messages to a text file
def log_to_file(log_message, log_file_path='logfile.txt'):
    """Function to log messages to a text file."""
    with open(log_file_path, 'a') as log_file:
        log_file.write(log_message + '\n')

def process_file(file_path):
    """Process a single file to replace text."""
    try:
        with open(file_path, "r", encoding="utf-8") as f:
            content = f.read()

        original_content = content
        for old, new in REPLACEMENTS.items():
            content = re.sub(re.escape(old), new, content)

        if content != original_content:
            with open(file_path, "w", encoding="utf-8") as f:
                f.write(content)
            log_to_file(f'Replaced text in {file_path}')
            return True
        else:
            log_to_file(f'No changes made to {file_path}')
            return False

    except Exception as e:
        log_to_file(f"Failed to process {file_path}: {e}")
        return False
    return False

def process_directory(directory):
    """Recursively process files in a directory."""
    total_files = 0
    successful_replacements = 0

    for root, dirs, files in os.walk(directory):
        # Ignore specified directories
        dirs[:] = [d for d in dirs if d not in IGNORE_DIRS]

        # Only process files in the target folders
        if any(target_folder in root for target_folder in TARGET_FOLDERS):
            for file in files:
                if file in IGNORE_FILES:
                    continue

                file_path = os.path.join(root, file)
                total_files += 1
                if process_file(file_path):
                    successful_replacements += 1

    return total_files, successful_replacements

def update_readme(directory):
    """Add metadata to README.md in the root directory."""
    readme_path = os.path.join(directory, "README.md")
    try:
        if os.path.exists(readme_path):
            with open(readme_path, "r+", encoding="utf-8") as f:
                content = f.read()
                f.seek(0, 0)
                f.write(README_METADATA + "\n" + content)
            log_to_file(f'Updated README.md at {readme_path}')
        else:
            with open(readme_path, "w", encoding="utf-8") as f:
                f.write(README_METADATA)
            log_to_file(f'Created and added metadata to README.md at {readme_path}')
    except Exception as e:
        log_to_file(f"Failed to update README.md: {e}")

def create_dockerfile(dockerfile_path='Dockerfile'):
    """Function to create or replace the Dockerfile with the given content."""
    try:
        with open(dockerfile_path, 'w') as dockerfile:
            dockerfile.write(DOCKERFILE_CONTENT)
        log_to_file(f'Dockerfile has been created/updated at {dockerfile_path}.')
    except Exception as e:
        log_to_file(f"Failed to create/update Dockerfile: {e}")

if __name__ == "__main__":
    repo_dir = os.getcwd()  # Root directory of the repository
    log_to_file('Script started.')

    print("Starting bulk text replacement...")

    total_files, successful_replacements = process_directory(repo_dir)
    update_readme(repo_dir)
    create_dockerfile()

    log_to_file('Script completed successfully.')

    print("\nBulk task completed!")
    print(f"Total files processed: {total_files}")
    print(f"Successful replacements: {successful_replacements}")

    log_to_file(f"Total files processed: {total_files}")
    log_to_file(f"Successful replacements: {successful_replacements}")