I want to check client information from firebase server and I used 3 Qthread but it doesn’t start when verification finished.
FireBaseServer class codes
`class FireBaseServer:
def init(self,parent):
self.reConnectFireBase()
self.parent = parent
def reConnectFireBase(self):
try:
firebaseConfig = {firebaseconfig}
fireBase = pyrebase.initialize_app(firebaseConfig)
self.dataBase = fireBase.database()
return True
except Exception as error:
return error
def checkAppStatus(self):
data = self.dataBase.child("accounts").get()
for values in data.each():
if str(values.val()["appId"]) == self.findAppId():
break
if values.val()["clientStatus"] == "false":
return False
elif values.val()["clientStatus"] == "true":
return True
def findAppId(self):
configFile = configparser.ConfigParser()
path = os.getenv('localappdata').replace("\","/")
listdir = os.listdir(path)
if "shopAppId.ini" in listdir:
configFile.read(path+"/shopAppId.ini")
return configFile['appId']['appid']
else:
return False
def checkLicenceVerification(self):
data = self.dataBase.child("accounts").get()
for values in data.each():
if str(values.val()["appId"]) == self.findAppId():
break
startingDate = values.val()["startingDate"]
licenceLength = values.val()["licenceLength"]
endingDate = datetime.datetime.strptime(startingDate,"%Y-%m-%d %H:%M:%S.%f")+datetime.timedelta(days=int(licenceLength))
now = datetime.datetime.now()
if now > endingDate:
self.dataBase.child("accounts").child(values.key()).update({"licenceStatus":"false"})
return False
else:
return True`
ServerChecker:
`class serverConnector(QMainWindow):
def init(self):
super().init()
self.ui = uis.serverConnecter()
self.ui.setupUi(self)
self.setFixedSize(self.width(),self.height())
self.ui.progressBar.valueChanged.connect(self.setLabelText)
global speed
#Threads
self.threadConnectFireBase = QThread(self)
self.threadConnectFireBase.run = self.connectFireBase
self.threadCheckAppStatus = QThread(self)
self.threadCheckAppStatus.run = self.checkAppStatus
self.threadCheckLicenceVerification = QThread(self)
self.threadCheckLicenceVerification.run = self.checkLicenceInfo
self.fireBaseServer = FireBaseServer(self)
self.threadConnectFireBase.start()
self.timer = QTimer(self)
def setLabelText(self):
val = self.ui.progressBar.value()
if val == 100:
self.goToMain()
def connectFireBase(self):
self.ui.progressBar.setValue(1)
self.ui.label.setText("Sunucu bağlantısı istendi.")
bool = self.fireBaseServer.reConnectFireBase()
if self.fireBaseServer.reConnectFireBase() == True:
self.ui.progressBar.setValue(5)
self.ui.label.setText("Sunucu bağlantısı kuruldu.")
self.threadCheckAppStatus.start()
self.threadConnectFireBase.quit()
else:
QMessageBox.critical(self,"Hata","Sunucuya bağlanırken hata oluştu. Hata: {}".format(bool))
self.close()
def checkAppStatus(self):
time.sleep(1)
self.ui.label.setText("Uygulama durumu kontrol ediliyor...")
if self.fireBaseServer.checkAppStatus() == False:
self.ui.progressBar.setValue(35)
self.ui.label.setText("Uygulama durumu doğrulandı.")
self.threadCheckLicenceVerification.start()
self.threadCheckAppStatus.quit()
else:
QMessageBox.critical(self,"Hata","Uygulama durumu doğrulanamadı. Hata: Uygulama başka bir cihazda açık yada önceki oturum doğru kapatılmadı.")
self.close()
def checkLicenceInfo(self):
time.sleep(1)
self.ui.label.setText("Lisansınız kontrol ediliyor...")
if self.fireBaseServer.checkLicenceVerification():
self.ui.label.setText("Doğrulama tamamlandı. Uygulama başlatılıyor.")
self.ui.progressBar.setValue(100)
#self.threadCheckLicenceVerification.quit()
else:
QMessageBox.critical(self,"Hata","Lisansınız doğrulanamadı.")
self.close()
def goToMain(self):
self.window = Main()
self.window.setWindowTitle("Mağaza Seç")
self.window.showMaximized()
self.window.setWindowIcon(QIcon("images/openfolder.png"))`
Furkan Eruzun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.