-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
251 lines (207 loc) · 7.47 KB
/
run.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import os
import subprocess
import mysql.connector
from dotenv import dotenv_values
from time import sleep
from sys import exit as error
from colorama import (
Fore,
init
)
class Color:
RED = Fore.RED
GREEN = Fore.GREEN
CYAN = Fore.CYAN
MAGENTA = Fore.MAGENTA
WHITE = Fore.WHITE
class Config(Color):
def __init__(self, _username: str = str(), _password: str = str(), _distro: int = int()) -> None:
self._clear()
print(self._banner())
sleep(1)
# Checking Username
if _username is str():
error(f"{Config.RED}[!] {Config.CYAN}Invalid Username For MySQL")
self._USERNAME: str = _username
# Checking Password
if _password is str():
error(f"{Config.RED}[!] {Config.CYAN}Invalid Password For MySQL")
self._PASSWORD: str = _password
# Checking Distro
if _distro not in range(1, 5):
error(f"{Config.RED}[!] {Config.CYAN}Invalid Distro")
self._DISTRO: str = _distro
# Checking MySQL Package
self._mysql_help() if self._check_mysql() is False else print(
f"{Config.GREEN}[+] {Config.CYAN}MySQL Package Is Valid On Your System"
)
sleep(1)
# Checking GoLang package
self._golang_help if self._check_golang() is False else print(
f"{Config.GREEN}[+] {Config.CYAN}GoLang Package Is Valid On Your System"
)
sleep(1)
# Checking Directories And Files
self._check_directory_file()
# ConfigMySQL
self._config_mysql()
# Creating Executable File Of main.go
print(
f"{Config.GREEN}[+] {Config.CYAN}Creating Executable File Of main.go"
)
os.system("go build ./main.go")
def _banner(self) -> str:
return f"""
{Color.CYAN} __ __ _ _ _ _
{Color.GREEN} \ \ / / __(_) |_ ___| | | |_ __
{Color.MAGENTA} \ \ /\ / / '__| | __/ _ \ | | | '_ \
{Color.RED} \ V V /| | | | || __/ |_| | |_) |
{Color.WHITE} \_/\_/ |_| |_|\__\___|\___/| .__/
|_|
"""
def _check_mysql(self) -> bool:
RESULT: str = subprocess.run(
"command -v mysql",
shell=True,
capture_output=True,
).stdout.decode()
return False if RESULT is str() else True
def _check_golang(self) -> bool:
RESULT: str = subprocess.run(
"command -v go",
shell=True,
capture_output=True,
).stdout.decode()
return False if RESULT is str() else True
def _golang_help(self) -> None:
match self._DISTRO:
case 1: # Debian
error(
f"{Config.RED}[!] {Config.CYAN}Please Install GoLang Package On Your System With -> [dpkg , apt , ...]"
)
case 2: # Arch
error(
f"{Config.RED}[!] {Config.CYAN}Please Install GoLang Package On Your System With -> [pacman , yay , ...]"
)
case 3: # Fedora
error(
f"{Config.RED}[!] {Config.CYAN}Please Install GoLang Package On Your System With -> [dnf , yum , ...]"
)
case 4: # Another
error(
f"{Config.RED}[!] {Config.CYAN}Please Install GoLang Package On Your System With Your Package Manager"
)
def _mysql_help(self) -> None:
match self._DISTRO:
case 1: # Debian
error(
f"{Config.RED}[!] {Config.CYAN}Please Install MySQL Package On Your System With -> [dpkg , apt , ...]"
)
case 2: # Arch
error(
f"{Config.RED}[!] {Config.CYAN}Please Install MySQL Package On Your System With -> [pacman , yay , ...]"
)
case 3: # Fedora
error(
f"{Config.RED}[!] {Config.CYAN}Please Install MySQL Package On Your System With -> [dnf , yum , ...]"
)
case 4: # Another
error(
f"{Config.RED}[!] {Config.CYAN}Please Install MySQL Package On Your System With Your Package Manager"
)
def _check_directory_file(self) -> None:
DIRS: tuple = (
"log",
"src",
"src/structure",
"src/telegram",
"src/discord",
"src/request",
"src/config",
"src/sql",
"static",
"static/txt",
)
FILES: tuple = (
"go.mod",
"go.sum",
"main.go",
"log/log.log",
"src/config/config.go",
"src/structure/channel.go",
"src/structure/secret.go",
"src/structure/items.go",
"src/structure/rss.go",
"src/telegram/telegram.go",
"src/discord/discord.go",
"src/request/request.go",
"src/sql/sql.go",
"static/txt/urls.txt",
)
for directory in DIRS:
error(
f"{Config.RED}[-] {Config.CYAN}Invalid Directory ({directory})"
) if os.path.exists(directory) is False else print(
f"{Config.GREEN}[+] {Config.CYAN}Valid Directory ({directory})"
)
sleep(1)
for file in FILES:
error(
f"{Config.RED}[-] {Config.CYAN}Invalid File ({file})"
) if os.path.exists(file) is False else print(
f"{Config.GREEN}[+] {Config.CYAN}Valid File ({file})"
)
sleep(1)
def _config_mysql(self) -> None:
database = mysql.connector.connect(
host="localhost",
user=self._USERNAME,
password=self._PASSWORD
)
cursor = database.cursor()
cursor.execute(
f"CREATE database IF NOT EXISTS WriteUp"
)
database.commit()
[... for _ in cursor]
cursor.close()
database = mysql.connector.connect(
host="localhost",
user="root",
password=self._PASSWORD,
database="WriteUp"
)
cursor = database.cursor()
cursor.execute(
"CREATE TABLE if not exists MYSQL_USER_PASS (username VARCHAR(300), password VARCHAR(300))"
)
cursor.execute(
"INSERT INTO MYSQL_USER_PASS (username,password) VALUES (%s, %s)",
(
'root',
self._PASSWORD
)
)
database.commit()
[... for _ in cursor]
cursor.execute(
"CREATE TABLE IF NOT EXISTS data (Title VARCHAR(300), Link VARCHAR(300), PublishDate VARCHAR(300))"
)
database.commit()
[... for _ in cursor]
cursor.execute(
"SELECT username, password FROM MYSQL_USER_PASS GROUP BY username, password"
)
[... for _ in cursor]
def _clear(self) -> None:
os.system("clear")
def main() -> None:
ENV: dict = dotenv_values("config.env")
Config(
ENV["MYSQL_USERNAME"],
ENV["MYSQL_PASSWORD"],
int(ENV["DISTRO"]),
)
if __name__ == "__main__":
init(autoreset=True)
main()