-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphid.py
More file actions
285 lines (228 loc) · 9.67 KB
/
phid.py
File metadata and controls
285 lines (228 loc) · 9.67 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
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtPrintSupport import *
import phonenumbers
from phonenumbers import carrier,geocoder,timezone
import sys,sqlite3,time
import random
import array
import os
class InsertDialog(QDialog):
def __init__(self, *args, **kwargs):
super(InsertDialog, self).__init__(*args, **kwargs)
self.QBtn = QPushButton()
self.QBtn.setText("Generate")
self.setWindowTitle("Find Number")
self.setFixedWidth(300)
self.setFixedHeight(250)
self.QBtn.clicked.connect(self.additem)
layout = QVBoxLayout()
self.nameinput = QLineEdit()
self.nameinput.setPlaceholderText("Mobile Number with Country Code")
layout.addWidget(self.nameinput)
layout.addWidget(self.QBtn)
self.setLayout(layout)
def additem(self):
mobileno = self.nameinput.text()
phno=mobileno
mobileno = phonenumbers.parse(mobileno,"CH")
timez=timezone.time_zones_for_number(mobileno)
carr=carrier.name_for_number(mobileno,"en")
geoc=geocoder.description_for_number(mobileno,"en")
valido=phonenumbers.is_valid_number(mobileno)
possi=phonenumbers.is_possible_number(mobileno)
if "Asia/Calcutta" in timez:
timez="India/Calcutta"
else:
timez="Outside India"
if valido==1:
valido="Yes"
else:
valido="No"
if possi==1:
possi="True"
else:
possi="False"
try:
self.conn = sqlite3.connect("prem.db")
self.c = self.conn.cursor()
self.c.execute("INSERT INTO phid (phno,timezone,carrier,geocoder,valid,poss) VALUES (?,?,?,?,?,?)",(phno,timez,carr,geoc,valido,possi))
self.conn.commit()
self.c.close()
self.conn.close()
QMessageBox.information(QMessageBox(),'Successful','Processed Successfully')
self.close()
except:
QMessageBox.information(QMessageBox(),'Error','Enter Valid Mobile Number')
class DeleteDialog(QDialog):
def __init__(self, *args, **kwargs):
super(DeleteDialog, self).__init__(*args, **kwargs)
self.QBtn = QPushButton()
self.QBtn.setText("Delete")
self.setWindowTitle("Delete Item")
self.setFixedWidth(300)
self.setFixedHeight(100)
self.QBtn.clicked.connect(self.deletestudent)
layout = QVBoxLayout()
self.deleteinput = QLineEdit()
self.onlyInt = QIntValidator()
self.deleteinput.setValidator(self.onlyInt)
self.deleteinput.setPlaceholderText("Id")
layout.addWidget(self.deleteinput)
layout.addWidget(self.QBtn)
self.setLayout(layout)
def deletestudent(self):
delrol = ""
delrol = self.deleteinput.text()
try:
self.conn = sqlite3.connect("prem.db")
self.c = self.conn.cursor()
self.c.execute("DELETE from phid WHERE id="+str(delrol))
self.conn.commit()
self.c.close()
self.conn.close()
QMessageBox.information(QMessageBox(),'Successful','Deleted From Table Successful')
self.close()
except Exception:
QMessageBox.warning(QMessageBox(), 'Error', 'Could not Delete item from the database.')
class SearchDialog(QDialog):
def __init__(self, *args, **kwargs):
super(SearchDialog, self).__init__(*args, **kwargs)
self.QBtn = QPushButton()
self.QBtn.setText("Search")
self.setWindowTitle("Find")
self.setFixedWidth(300)
self.setFixedHeight(100)
self.QBtn.clicked.connect(self.searchitem)
layout = QVBoxLayout()
self.searchinput = QLineEdit()
self.onlyInt = QIntValidator()
self.searchinput.setValidator(self.onlyInt)
self.searchinput.setPlaceholderText("Id")
layout.addWidget(self.searchinput)
layout.addWidget(self.QBtn)
self.setLayout(layout)
def searchitem(self):
searchrol = ""
searchrol = self.searchinput.text()
try:
self.conn = sqlite3.connect("prem.db")
self.c = self.conn.cursor()
result = self.c.execute("SELECT * from phid WHERE id="+str(searchrol))
row = result.fetchone()
searchresult = "Id : "+str(row[0])+'\n'+"Mobile Number : "+str(row[1])+'\n'+"TimeZone : "+str(row[2])+'\n'+"Carrier : "+str(row[5]+'\n'+"Geocoder : "+str(row[6])+'\n'+"Valid : "+str(row[3])+'\n'+"Possibility : "+str(row[3]))
QMessageBox.information(QMessageBox(), 'Successful', searchresult)
self.conn.commit()
self.c.close()
self.conn.close()
except Exception:
QMessageBox.warning(QMessageBox(), 'Error', 'Could not Find item from the database.')
class LoginDialog(QDialog):
def __init__(self, *args, **kwargs):
super(LoginDialog, self).__init__(*args, **kwargs)
self.setFixedWidth(500)
self.setFixedHeight(250)
layout = QVBoxLayout()
self.passinput = QLineEdit()
self.passinput.setEchoMode(QLineEdit.Password)
self.passinput.setPlaceholderText("Enter Password.")
self.QBtn = QPushButton()
self.QBtn.setText("Login")
self.setWindowTitle('Login')
self.QBtn.clicked.connect(self.login)
title = QLabel("Login")
font = title.font()
font.setPointSize(16)
title.setFont(font)
title.setAlignment(Qt.AlignCenter)
layout.addWidget(title)
layout.addWidget(self.passinput)
layout.addWidget(self.QBtn)
self.setLayout(layout)
def login(self):
if(self.passinput.text() == "premkvkv"):
self.accept()
else:
QMessageBox.warning(self, 'Error', 'Wrong Password')
exit()
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.conn = sqlite3.connect("prem.db")
self.c = self.conn.cursor()
self.c.close()
self.setWindowTitle("Password Generator")
self.setMinimumSize(800, 600)
self.tableWidget = QTableWidget()
self.setCentralWidget(self.tableWidget)
self.tableWidget.setAlternatingRowColors(True)
self.tableWidget.setColumnCount(7)
self.tableWidget.horizontalHeader().setCascadingSectionResizes(False)
self.tableWidget.horizontalHeader().setSortIndicatorShown(False)
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.verticalHeader().setVisible(False)
self.tableWidget.verticalHeader().setCascadingSectionResizes(False)
self.tableWidget.verticalHeader().setStretchLastSection(False)
self.tableWidget.setHorizontalHeaderLabels(("id", "Mobile Nummber", "Timezone", "carrier","Country","Valid","Possibility"))
toolbar = QToolBar()
toolbar.setMovable(False)
self.addToolBar(toolbar)
statusbar = QStatusBar()
self.setStatusBar(statusbar)
btn_ac_adduser = QAction(QIcon("icon/add.png"), "New Generate", self)
btn_ac_adduser.triggered.connect(self.insert)
btn_ac_adduser.setStatusTip("Add Student")
toolbar.addAction(btn_ac_adduser)
btn_ac_refresh = QAction(QIcon("icon/refresh.png"),"Refresh",self)
btn_ac_refresh.triggered.connect(self.loaddata)
btn_ac_refresh.setStatusTip("Refresh Table")
toolbar.addAction(btn_ac_refresh)
btn_ac_search = QAction(QIcon("icon/search.png"), "Search", self)
btn_ac_search.triggered.connect(self.search)
btn_ac_search.setStatusTip("Search User")
toolbar.addAction(btn_ac_search)
btn_ac_delete = QAction(QIcon("icon/trash.png"), "Delete", self)
btn_ac_delete.triggered.connect(self.delete)
btn_ac_delete.setStatusTip("Delete User")
toolbar.addAction(btn_ac_delete)
def loaddata(self):
self.connection = sqlite3.connect("prem.db")
query = "SELECT * FROM phid"
result = self.connection.execute(query)
self.tableWidget.setRowCount(0)
for row_number, row_data in enumerate(result):
self.tableWidget.insertRow(row_number)
for column_number, data in enumerate(row_data):
self.tableWidget.setItem(row_number, column_number,QTableWidgetItem(str(data)))
self.connection.close()
def handlePaintRequest(self, printer):
document = QTextDocument()
cursor = QTextCursor(document)
model = self.table.model()
table = cursor.insertTable(
model.rowCount(), model.columnCount())
for row in range(table.rows()):
for column in range(table.columns()):
cursor.insertText(model.item(row, column).text())
cursor.movePosition(QTextCursor.NextCell)
document.print_(printer)
def insert(self):
dlg = InsertDialog()
dlg.exec_()
def delete(self):
dlg = DeleteDialog()
dlg.exec_()
def search(self):
dlg = SearchDialog()
dlg.exec_()
def about(self):
dlg = AboutDialog()
dlg.exec_()
app = QApplication(sys.argv)
passdlg = LoginDialog()
if(passdlg.exec_() == QDialog.Accepted):
window = MainWindow()
window.show()
window.loaddata()
sys.exit(app.exec_())