-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
280 lines (234 loc) · 9.52 KB
/
main.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
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
from corpor_truepeople import Copor_TrueSearch
from truepeoplesearh import TruepeopleSearch
from corporationwiki import CorporSearch
from PyQt5.QtCore import QSize
from threading import Thread
from PyQt5 import QtWidgets
import qtawesome as qta
from PyQt5 import uic
import qdarkstyle
import sys
import os
qtCreatorFile = os.path.join(os.getcwd(), 'src', 'main.ui')
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class LeadGenerator(QtWidgets.QDialog, Ui_MainWindow):
checkboxStatus = ""
def __init__(self):
QtWidgets.QDialog.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self._setup_icons()
self.make_connections()
self.corpChkBox.setChecked(True)
self.t1 = None # CorporationWiki Search
self.t2 = None # Truepoeple Search
self.t3 = None # Corporation -> Truepeople Search
self.pause_handler = None
self._setProgress(0)
self.setStyleSheet(
"QLabel#label {font: bold 20px;}"
"QGroupBox {font: bold 14px;}"
"QCheckBox {font: 12px;}"
"QTextEdit#logTextEdit {font: 15px;}"
)
def _set_icon(self, widget: QtWidgets.QWidget, icon_name: str, text: str = None):
widget.setIcon(qta.icon(icon_name, color='white'))
self.searchPushBtn.setIconSize(QSize(20, 20))
if text:
widget.setText(text)
def _setup_icons(self):
self._set_icon(self.resetPushBtn, 'mdi.reload')
self._set_icon(self.togStatePushBtn, 'mdi.play')
self._set_icon(self.searchPushBtn, 'mdi.account-search')
def _handle_chk_box(self, state: bool):
if state:
_widgets_by_option = {
'Truepeoplesearch.com': [
self.nameLabel,
self.nameLineEdit,
self.adrLabel,
self.adrLineEdit,
],
'Otherwise': [
self.keyLabel,
self.keyLineEdit
]
}
sender = self.sender()
text = sender.text()
self.checkboxStatus = text
print(text, 'Selected')
_enabled_option = text if text == 'Truepeoplesearch.com' else 'Otherwise'
for option, widgets in _widgets_by_option.items():
for widget in widgets:
if option == _enabled_option:
widget.show()
else:
widget.hide()
self.resize(self.width(), self.minimumHeight())
def _start_task(self):
sender = self.sender()
print('{text} Button Clicked'.format(text=sender.text()))
# Corporationwiki
searchKey = self.keyLineEdit.text()
# TruepeopleSearch
searchName = self.nameLineEdit.text()
searchAddress = self.adrLineEdit.text()
self._set_icon(self.togStatePushBtn, 'mdi.stop', 'Stop')
if self.checkboxStatus == "Corporationwiki.com":
if searchKey == "":
QtWidgets.QMessageBox.about(self, "Warning", "Please insert Search Key")
else:
print(self.logTextEdit)
self.t1 = self.do_crawl_corpor(searchKey)
elif self.checkboxStatus == "Truepeoplesearch.com":
if searchKey == "" and (searchName == "" and searchAddress == ""):
QtWidgets.QMessageBox.about(self, "Warning", "Please insert `Name` and `Address`")
else:
print(searchName, searchAddress)
self.t2 = self.do_crawl_truepeople(searchName, searchAddress)
elif self.checkboxStatus == "Corporationwiki → Truepeoplesearch":
if searchKey == "":
QtWidgets.QMessageBox.about(self, "Warning", "Please insert `Search Key`")
else:
self.t3 = self.do_crawl_corpor_true(searchKey)
self._set_icon(self.togStatePushBtn, 'mdi.stop', 'Stop')
def _reset(self):
if self.t1:
self.t1.logcallback.disconnect()
self.t1.driver.close()
self.t1.driver.quit()
self.t1.driver = None
self.t1 = None
if self.t2:
self.t2.logcallback.disconnect()
self.t2.driver.close()
self.t2.driver.quit()
self.t2.driver = None
self.t2.driver1.close()
self.t2.driver1.quit()
self.t2.driver1 = None
self.t2.driver2.close()
self.t2.driver2.quit()
self.t2.driver2 = None
self.t2 = None
if self.t3:
self.t3.logcallback.disconnect()
self.t3.driver.close()
self.t3.driver.quit()
self.t3.driver = None
self.t3.driver1.close()
self.t3.driver1.quit()
self.t3.driver1 = None
self.t3.driver2.close()
self.t3.driver2.quit()
self.t3.driver2 = None
self.t3.driver3.close()
self.t3.driver3.quit()
self.t3.driver3 = None
self.t3 = None
self.logTextEdit.append('_____________________Reset Done')
def _reset_task(self):
self.logTextEdit.append('_____________________Resetting (Please Wait...)')
worker = Thread(target=self._reset)
worker.start()
sender = self.sender()
print('{text} Button Clicked'.format(text=sender.text()))
self._set_icon(self.togStatePushBtn, 'mdi.play', 'Play')
self._setProgress(0)
if self.checkboxStatus == "Corporationwiki.com" or self.checkboxStatus == "Corporationwiki → Truepeoplesearch":
self.keyLineEdit.setText(None)
elif self.checkboxStatus == "Truepeoplesearch.com":
self.nameLineEdit.setText(None)
self.adrLineEdit.setText(None)
def _toggle_task(self):
sender = self.sender()
print('{text} Button Clicked'.format(text=sender.text()))
if not self.t1 and not self.t2 and not self.t3:
self.logTextEdit.append('No Task Running')
return
if sender.text() == 'Play':
self.logTextEdit.append('_____________________Resuming Task')
if self.t1:
# Resuming Task
self.t1.paused = False
elif self.t2:
self.t2.paused = False
elif self.t3:
self.t3.paused = False
self._set_icon(sender, 'mdi.stop', 'Stop')
elif sender.text() == 'Stop':
self._set_icon(sender, 'mdi.play', 'Play')
self.logTextEdit.append('_____________________Pausing Task')
if self.t1:
# Pausing Task
self.t1.paused = True
elif self.t2:
self.t2.paused = True
elif self.t3:
self.t3.paused = True
def _exit_task(self):
# if self.t1:
# self.t1.driver.quit()
# self.t1.driver = None
# self.t1 = None
# elif self.t2:
# self.t2.driver.quit()
# self.t2.driver = None
# self.t2.driver1.quit()
# self.t2.driver1 = None
# self.t2.driver2.quit()
# self.t2.driver2 = None
# self.t2 = None
# (Change to fix close crash)
self.logTextEdit.append('_____________________Closing (Please Wait...)')
t = Thread(target=self._reset)
t.setDaemon(True)
t.start()
from PyQt5.QtCore import QCoreApplication
while t.is_alive():
QCoreApplication.processEvents()
self.close()
def _setProgress(self, percent: int):
self.progressBar.setValue(percent)
def do_crawl_corpor(self, keyword):
# print("param name: {}".format(keyword))
# print("param log callback: {}".format(self.addLogMessage))
corporSearch = CorporSearch(keyword)
corporSearch.logcallback.connect(self.addLogMessage)
corporSearch.start()
return corporSearch
def do_crawl_truepeople(self, keyName, keyAddress):
# print("param name: {}".format(keyName), "param address: {}".format(keyAddress))
# print("param log callback: {}".format(self.addLogMessage))
truepeopleSearch = TruepeopleSearch(keyName, keyAddress)
truepeopleSearch.logcallback.connect(self.addLogMessage)
truepeopleSearch.start()
return truepeopleSearch
def do_crawl_corpor_true(self, keyword):
corpor_trueSearch = Copor_TrueSearch(keyword)
corpor_trueSearch.logcallback.connect(self.addLogMessage)
corpor_trueSearch.start()
return corpor_trueSearch
def make_connections(self):
# Check Boxes
self.corpChkBox.toggled.connect(self._handle_chk_box)
self.peopleChkBox.toggled.connect(self._handle_chk_box)
self.peopleCorpChkBox.toggled.connect(self._handle_chk_box)
# Push Button
self.resetPushBtn.clicked.connect(self._reset_task)
self.searchPushBtn.clicked.connect(self._start_task)
self.togStatePushBtn.clicked.connect(self._toggle_task)
# Close Button
# self.buttonBox.clicked.connect(self._exit_task)
self.closePushBtn.clicked.connect(self._exit_task)
def addLogMessage(self, message, status):
self.logTextEdit.append(message)
self._setProgress(status)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
window = LeadGenerator()
window.setWindowTitle('Lead Generator')
window.show()
sys.exit(app.exec_())