-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBackSEOApplicationManager.py
More file actions
executable file
·412 lines (385 loc) · 14.8 KB
/
BackSEOApplicationManager.py
File metadata and controls
executable file
·412 lines (385 loc) · 14.8 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
from BackSEOSettings import BackSEOSettings
import regex
import os
import aiohttp
import dearpygui.dearpygui as dpg
import inspect
import time
import concurrent.futures
import multiprocessing
from multiprocessing import Queue, pool
import threading
from typing import Any, Dict, List, Union
from BackSEODataHandler import *
from core import BackSEOApp
from core_ui import InspectResults as _InspectResults, Audit as _Audit
from core_ui import Core_UI
from SEO import Local as _Local
from SEO.Agency import Agency as _Agency
from FlaskApp import FlaskApp as _FlaskApp
# import cython
class BackSEOApplicationManager:
_app: BackSEOApp
InspectResults: _InspectResults.CoreInspectResults
Audit: _Audit.CoreAudit
Local: _Local.Local
Agency: _Agency
FlaskApp: _FlaskApp
def __init__(self) -> None:
self._app = BackSEOApp()
# self.Editor = Editor.CoreEditor()
self.InspectResults = _InspectResults.CoreInspectResults()
self.Audit = _Audit.CoreAudit()
self.Local = _Local.Local()
self.Agency = _Agency()
self.FlaskApp = _FlaskApp(self.Agency)
self.FlaskApp.run(debug=False)
self.modules: Dict[str, Core_UI] = dict()
self.tabs: Dict[str, int | str] = dict()
self.menus: Dict[str, int | str] = dict()
self.windows: Dict[str, int | str] = dict()
self.commandQ: List[str] = list()
self.commandQDone: List[str] = list()
self.commandQC: List[str] = list()
self.curCommand: str = ""
self.doRunCommands: bool = False
self.commandComplete: bool = False
self.commandRunning: bool = False
self.backDataHandler: BackSEODataHandler = getBackSEODataHandler()
self.modules["Core"] = self._app
self.modules["Agency"] = self.Agency
# self.modules["Editor"] = self.Editor
self.modules["InspectResults"] = self.InspectResults
self.modules["Audit"] = self.Audit
self.modules["Local"] = self.Local
self.addQueues()
self._app.run()
self.setTabs()
self.setMenus()
self.setWindows()
self.mainTab: int | str = self._app.mainTabBar
def addQueues(self) -> None:
for name, module in self.modules.items():
module.add_queues(self.commandQ)
def setTabs(self) -> None:
for name, module in self.modules.items():
self.tabs[name] = module.create_tab(self._app.mainTabBar, self._app.options)
module.addRealPrimaryWindow(self._app.backSEOCoreWin)
def setMenus(self) -> None:
for name, module in self.modules.items():
self.menus[name] = module.create_menu(
self._app.mainMenu, before=self._app.toolsMenu
)
def setWindows(self) -> None:
for name, module in self.modules.items():
self.windows[name] = module.create_window()
def updateUDatas(self) -> None:
for name, module in self.modules.items():
module.updateUData()
def update(self, piece: str, data: Any) -> None:
for name, module in self.modules.items():
module.update(piece, data)
def running_animation(self) -> None:
# r: cython.double
# g: cython.double
# b: cython.double
# a: cython.double
# directi: cython.int
# y: cython.int
# transparency: cython.int
# i: cython.int
if not self.doRunCommands:
return
transparency = 0
myText: int | str = dpg.draw_text(
text="Automating...",
pos=(0, 0),
color=[255, 255, 255, transparency],
parent=self._app.animations,
size=20,
)
direction = 3
myballs = list()
r, g, b, a = (0, 0, 0, 255)
y = 0
directi = 1
for i in range(20):
if i % 3 == 0:
r += 3
g += 27
b += 5
elif i % 3 == 1:
r += 56
g += 22
b += 1
elif i % 3 == 2:
r += 19
b += 2
g += 3
if r > 255:
r = i / 2
if g > 255:
g = i / 3
if b > 255:
b = i / 4
y += directi
if y > 26:
directi = -1
elif y < 0:
directi = 1
myballs.append(
dpg.draw_circle(
center=(i * 5 + 170, y),
radius=2,
user_data=(i * 5 + 170, y, i % 3, 1, (r, g, b, a)),
color=[r, g, b, a],
fill=[r, g, b, a],
parent=self._app.animations,
)
)
while dpg.is_dearpygui_running() and self.doRunCommands:
transparency += direction
if transparency > 254:
direction = -3
elif transparency < 1:
direction = 3
if transparency > 200:
theText = "Automating..."
elif transparency > 140:
theText = "Automating.."
elif transparency > 100:
theText = "Automating."
else:
theText = "Automating"
dpg.configure_item(
myText, text=theText, color=[255, 255, 255, transparency]
)
for ball in myballs:
self.doUpDown(ball)
time.sleep(0.03)
# dpg.render_dearpygui_frame()
dpg.delete_item(self._app.animations, children_only=True)
def doUpDown(self, item: int | str) -> None:
# x: cython.int
# y: cython.int
# i: cython.int
# verti: cython.int
# c: tuple
# r: cython.double
# g: cython.double
# b: cython.double
# a: cython.double
x, y, i, verti, c = dpg.get_item_user_data(item)
x += 10
if x > 700:
x = 170
if y > 26:
verti = -1
elif y < 0:
verti = 1
y += verti
r, g, b, a = c
if i % 3 == 0:
r += 3
g += 27
b += 5
elif i % 3 == 1:
r += 56
g += 22
b += 1
elif i % 3 == 2:
r += 19
b += 2
g += 3
if r > 255:
r = i / 2
if g > 255:
g = i / 3
if b > 255:
b = i / 4
dpg.configure_item(
item,
center=(x, y),
color=[r, g, b, a],
fill=[r, g, b, a],
user_data=(x, y, i, verti, (r, g, b, a)),
)
def runCommands(self, *args, **kwargs) -> None:
"""
This function runs the commands in the command queue.
The command queue is a list of tuples that automate the core UI
It only runs one command per frame cycle and won't run the next until it
is confirmed complete. This is to prevent the UI from freezing.
There are helper functions that make the process a lot easier. They are:
- swapTab
- inputSearch (
InspectResults: searchkeyword, searchProxy, numResult -> startSearch -> createSearchReport
Audit: auditInput, searchProxy -> startAudit -> createAllAuditReport
Local: localKeyword, proxy, localLocation, nodeDistance -> updateMap -> outputFrame
)
- generateFullReport
"""
if "START RUNNING" in self.commandQ:
self.doRunCommands = True
myT = threading.Thread(target=self.running_animation)
myT.start()
self.commandQ.remove("START RUNNING")
# print("START RUNNING")
if "STOP" in self.commandQ:
self.doRunCommands = False
self.commandQ.remove("STOP")
# print("STOP")
return
if "JUST ANIMATIONS" in self.commandQ:
return
if "RUN ANIMATIONS" in self.commandQ:
self.commandQ.remove("RUN ANIMATIONS")
self.commandQ.append("JUST ANIMATIONS")
self.doRunCommands = True
myT = threading.Thread(target=self.running_animation)
myT.start()
# print("RUN ANIMATIONS")
return
if self.doRunCommands:
if self.commandRunning:
if self.InspectResults.searching:
return
elif self.Audit.auditing:
return
elif self.Local.locked:
return
else:
self.commandComplete = True
self.doCommand(self.curCommand)
self.commandRunning = False
self.curCommand = ""
self.commandQDone.append(self.curCommand)
return
if len(self.commandQ) > 0:
if len(self.commandQC) == 0:
self.commandQC = self.commandQ.copy()
self.commandQC.reverse()
self.curCommand = self.commandQC.pop()
if len(self.commandQC) == 0:
self.doRunCommands = False
self.doCommand(self.curCommand)
def doCommand(self, command: str, *args, **kwargs) -> None:
# print("Entered Do Command")
commandparts: list[str] = command.split("|")
if commandparts[0] == "swapTab":
# print("Swapping Tab")
self.swapTab(commandparts[1])
elif commandparts[0] == "inputSearchInspectResults":
self.inputSearchInspectResults(
commandparts[1],
commandparts[2],
int(commandparts[3]),
commandparts[4],
commandparts[5],
)
elif commandparts[0] == "inputSearchAudit":
self.inputSearchAudit(commandparts[1], commandparts[2], commandparts[3])
elif commandparts[0] == "inputSearchLocal":
self.inputSearchLocal(
commandparts[1],
commandparts[2],
commandparts[3],
commandparts[4],
commandparts[5],
)
elif commandparts[0] == "FINALIZE":
self.Agency.finalizeReport(commandparts[1])
def swapTab(self, tabName: str, *args, **kwargs) -> None:
"""
This function swaps the tab to the tabName passed in.
Example:
swapTab("Audit")
"""
if tabName in self.tabs:
dpg.set_value(self._app.mainTabBar, self.tabs[tabName])
def inputSearchInspectResults(
self,
searchkeyword: str,
searchProxy: str,
numResult: int,
client: str = "",
clientSite: str = "",
) -> None:
"""
This function inputs the searchkeyword, searchProxy, and numResult into the InspectResults tab.
Example:
inputSearchInspectResults("keyword", "proxy", 100)
"""
if not self.commandRunning:
# print(f"searchkeyword: {searchkeyword}, searchProxy: {searchProxy}, numResult: {numResult}")
dpg.set_value(self.InspectResults.searchkeyword, searchkeyword)
dpg.set_value(self.InspectResults.searchProxy, searchProxy)
dpg.set_value(self.InspectResults.numResult, numResult)
self.InspectResults.startSearch()
self.commandRunning = True
else:
# print(f"Creating Search Report for {searchkeyword}")
self.InspectResults.createSearchReport(searchkeyword, client, clientSite)
if not self.commandRunning and not self.doRunCommands:
self.Agency.finalizeReport()
# Audit: auditInput, searchProxy -> startAudit -> createAllAuditReport
# Local: localKeyword, proxy, localLocation, nodeDistance -> updateMap -> outputFrame
def inputSearchAudit(
self, auditInput: str, searchProxy: str, client: str = ""
) -> None:
"""
This function inputs the auditInput and searchProxy into the Audit tab.
Example:
inputSearchAudit("keyword", "proxy")
"""
if not self.commandRunning:
# print(f"auditInput: {auditInput}, searchProxy: {searchProxy}")
dpg.set_value(self.Audit.auditinput, auditInput)
dpg.set_value(self.Audit.searchProxy, searchProxy)
self.Audit.startAudit()
self.commandRunning = True
else:
# print(f"Creating Audit Report for {auditInput} {client}")
self.Audit.createAllAuditReport(auditInput, client)
if not self.commandRunning and not self.doRunCommands:
self.Agency.finalizeReport()
def inputSearchLocal(
self,
localKeyword: str,
proxy: str,
localLocation: str,
nodeDistance: str,
client: str = "",
) -> None:
"""
This function inputs the localKeyword, proxy, localLocation, and nodeDistance into the Local tab.
Example:
inputSearchLocal("keyword", "proxy", "location", "distance")
"""
if not self.commandRunning:
# print(f"localKeyword: {localKeyword}, proxy: {proxy}, localLocation: {localLocation}, nodeDistance: {nodeDistance}")
dpg.set_value(self.Local.localKeyword, localKeyword)
dpg.set_value(self.Local.proxy, proxy)
dpg.set_value(self.Local.localLocation, localLocation)
dpg.set_value(self.Local.nodeDistance, nodeDistance)
self.Local.updateMap()
self.commandRunning = True
else:
# print(f"Creating Local Report for {localKeyword} {client}")
businesses = self.Local.allBusinesses
clientFound = False
if client != "":
if client in businesses:
dpg.set_value(self.Local.businessBox, client)
clientFound = True
else:
for business in businesses:
if client in business:
dpg.set_value(self.Local.businessBox, business)
clientFound = True
break
if not clientFound:
return
self.Local.outputFrame(zoom=nodeDistance, client=client)
if not self.commandRunning and not self.doRunCommands:
self.Agency.finalizeReport()