From 2d2a2764a0fc3a4e9857f925df425e572ea2de32 Mon Sep 17 00:00:00 2001 From: BluTiGeS Date: Wed, 9 Jun 2021 16:42:01 +0200 Subject: [PATCH] adapted to mainline beta and further improvements READY to TEST --- tools/gui/qtcodegen.py | 85 ++++++++++++++++++++++++------------------ tools/gui/qtkontakt.py | 2 +- tools/utils.py | 9 ----- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/tools/gui/qtcodegen.py b/tools/gui/qtcodegen.py index 9a76856b..1ef25265 100644 --- a/tools/gui/qtcodegen.py +++ b/tools/gui/qtcodegen.py @@ -11,7 +11,7 @@ from tools.its import ImpfterminService from tools.kontaktdaten import validate_datum from tools.exceptions import MissingValuesError, ValidationError -from tools.utils import gen_random_code + PATH = os.path.dirname(os.path.realpath(__file__)) @@ -75,6 +75,19 @@ def __del__(self): def stop(self): self.stopped = True + # send a signal and wait for received return + def sendSignalAndWait(self, strSignal, strSigParam): + if strSignal == "signalShowInput": + self.signalShowInput.emit(strSigParam) + + while True and self.stopped is False: + if self.signalGot is True: + break + QtCore.QThread.msleep(100) + #reset member for next signal + self.signalGot = False + + def updateData(self, strmode, txt): if strmode == "GEBURTSDATUM": print(txt) @@ -105,49 +118,42 @@ def code_gen(self): if self.stopped is True: return False - # Erstelle Zufallscode nach Format XXXX-YYYY-ZZZZ - # für die Cookie-Generierung - random_code = gen_random_code() - print(f"Für die Cookies-Generierung wird ein zufälliger Code verwendet ({random_code}).\n") - - its = ImpfterminService(random_code, [self.plz_impfzentrum], {}, self.ROOT_PATH) + its = ImpfterminService([], {}, self.ROOT_PATH) # send signal for GUI - self.signalShowInput.emit("GEBURTSDATUM") - while True and self.stopped is False: - if self.signalGot is True: - break - QtCore.QThread.msleep(100) + self.sendSignalAndWait("signalShowInput","GEBURTSDATUM") - #reset member for next signal - self.signalGot = False - #stop requested in the meanwhile? if self.stopped is True: return False - # cookies erneuern und code anfordern - its.renew_cookies_code() - token = its.code_anfordern(self.mail, self.telefonnummer, self.plz_impfzentrum, self.geburtsdatum) - - if token is not None: - # code bestätigen - # 3 Versuche für die SMS-Code-Eingabe - self.signalShowInput.emit("SMSCODE") + # code anfordern + try: + token, cookies = its.code_anfordern(self.mail, self.telefonnummer, self.plz_impfzentrum, self.geburtsdatum) + except RuntimeError as exc: + print( + f"\nDie Code-Generierung war leider nicht erfolgreich:\n{str(exc)}") + self.signalShowDlg.emit("CRITICAL_CLOSE",f"\nDie Code-Generierung war leider nicht erfolgreich:\n{str(exc)}") while True and self.stopped is False: - if self.signalGot is True: - break QtCore.QThread.msleep(100) - - #stop requested in the meanwhile? - if self.stopped is True: - return False - - if its.code_bestaetigen(token, self.sms_pin): - self.signalShowInput.emit("SMSCODE_OK") - return True + return False - print( "Die Code-Generierung war leider nicht erfolgreich.") + # code bestätigen + # 3 Versuche für die SMS-Code-Eingabe + self.sendSignalAndWait("signalShowInput","SMSCODE") + + #stop requested in the meanwhile? + if self.stopped is True: + return False + + if its.code_bestaetigen(token, cookies, self.sms_pin, self.plz_impfzentrum): + self.sendSignalAndWait("signalShowInput","SMSCODE_OK") + return True + + print("\nSMS-Code ungültig") + print("Die Code-Generierung war leider nicht erfolgreich.") + + self.signalShowDlg.emit("CRITICAL_CLOSE",f"SMS-Code ungültig.\n\nDie Code-Generierung war leider nicht erfolgreich") return False @@ -236,8 +242,7 @@ def update_ausgabe(self, text): cursor.insertText(str("\n")) self.textAusgabe.setTextCursor(cursor) self.textAusgabe.ensureCursorVisible() - - + def showInputDlg(self, dlgType): if dlgType == "GEBURTSDATUM": @@ -266,6 +271,7 @@ def showInputDlg(self, dlgType): self.worker.signalUpdateData.emit("SMSCODE",sms_pin) elif dlgType == "SMSCODE_OK": QtWidgets.QMessageBox.information(self, "Erfolgreich", "Code erfolgreich generiert. Du kannst jetzt mit der Terminsuche fortfahren.") + self.worker.signalUpdateData.emit("SMSCODE_OK","") def showDlg(self, strMode, strTxt): if strMode == "MISSING_KONTAKT": @@ -273,6 +279,11 @@ def showDlg(self, strMode, strTxt): "Die Kontakdaten sind nicht korrekt!.\n\nBitte Datei neu erstellen!", QMessageBox.StandardButton.Ok) if ret == QMessageBox.StandardButton.Ok: self.hardClose() + elif strMode == "CRITICAL_CLOSE": + ret = QtWidgets.QMessageBox.critical(self, "Error", strTxt, QMessageBox.StandardButton.Ok) + if ret == QMessageBox.StandardButton.Ok: + self.hardClose() + # force to close the dialog without confirmation def hardClose(self): @@ -304,7 +315,7 @@ def closeEvent(self, event): #stop thread self.thread.quit() - self.thread.wait(5000) + self.thread.wait(3000) self.thread.terminate() # Streams wieder korrigieren, damit kein Fehler kommt diff --git a/tools/gui/qtkontakt.py b/tools/gui/qtkontakt.py index 17cf3ef4..47c35074 100644 --- a/tools/gui/qtkontakt.py +++ b/tools/gui/qtkontakt.py @@ -224,7 +224,7 @@ def __get_alle_werte(self) -> dict: if self.modus == Modus.TERMIN_SUCHEN: kontaktdaten = { "plz_impfzentren": plz_zentren, - "code": code, + "code": codes, "kontakt": { "anrede": anrede, "vorname": vorname, diff --git a/tools/utils.py b/tools/utils.py index 20e13759..d7801902 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -175,15 +175,6 @@ def get_latest_version(): latest_version = requests.get(json_url).json()['tag_name'] return latest_version -# Erstelle Zufallscode nach Format XXXX-YYYY-ZZZZ -# für die Cookie-Generierung -def gen_random_code(): - code_chars = string.ascii_uppercase + string.digits - one = 'VACC' - two = 'IPY' + random.choice(code_chars) - three = ''.join(random.choices(code_chars, k=4)) - random_code = f"{one}-{two}-{three}" - return random_code def pushover_notification(notifications: dict, title: str, message: str): if 'app_token' not in notifications or 'user_key' not in notifications: