From 0e8b47ebbe7d6bcc920991f101b57048a2d2f523 Mon Sep 17 00:00:00 2001 From: iamnotturner Date: Tue, 22 Jun 2021 00:24:53 +0200 Subject: [PATCH 1/3] disabled local chromedriver, replaced with google chrome or custom chromium installation --- main.py | 13 +++++++++++++ tools/its.py | 37 +++++++++++++------------------------ tools/utils.py | 2 -- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index bddcae8e..3141c45f 100755 --- a/main.py +++ b/main.py @@ -367,6 +367,11 @@ def gen_code(kontaktdaten): its = ImpfterminService([], {}, PATH) + # Einmal Chrome starten, um früh einen Fehler zu erzeugen, falls die + # erforderliche Software nicht installiert ist. + its.log.info("Prüfen von Chromium und Chromedriver") + its.get_chromedriver(headless=True).quit() + print("\nBitte trage nachfolgend dein Geburtsdatum im Format DD.MM.YYYY ein.\n" "Beispiel: 02.03.1982\n") while True: @@ -564,6 +569,14 @@ def main(): else: print("Falscheingabe! Bitte erneut versuchen.") print() + except TypeError as exc: + if str(exc) == "expected str, bytes or os.PathLike object, not NoneType": + print("\nChromium nicht gefunden. Zwei Möglichkeiten zur Problembehebung:\n" + "1) Google Chrome installieren: https://www.google.com/intl/de_de/chrome/\n" + "2) Chromium über das Vaccipy-Menü installieren: " + "'[3] Eigene Chromium Instanz im Vaccipy Ordner installieren'\n") + else: + print(f"\nUnbekannter TypeError:\n{str(exc)}\n") except Exception as exc: print(f"\nFehler:\n{str(exc)}\n") diff --git a/tools/its.py b/tools/its.py index aeec1d4e..d2269e3a 100644 --- a/tools/its.py +++ b/tools/its.py @@ -4,8 +4,8 @@ import platform import random import string -import sys import time + # Alphabetisch sortiert: from base64 import b64encode from datetime import datetime, date, timedelta @@ -26,7 +26,7 @@ from selenium.webdriver.support.ui import WebDriverWait from tools.chromium_downloader import webdriver_executable, \ - check_webdriver + check_webdriver, chromium_executable, check_chromium from tools.clog import CLogger from tools.exceptions import AppointmentGone, BookingError, TimeframeMissed, UnmatchingCodeError from tools.kontaktdaten import decode_wochentag, validate_codes, validate_kontakt, \ @@ -256,27 +256,11 @@ def get_chromedriver_path(self): if check_webdriver(): return webdriver_executable() - # Chromedriver anhand des OS auswählen - if 'linux' in self.operating_system: - if "64" in platform.architecture() or sys.maxsize > 2 ** 32: - return os.path.join(self.PATH, "tools/chromedriver/chromedriver-linux-64") - else: - return os.path.join(self.PATH, "tools/chromedriver/chromedriver-linux-32") - elif 'windows' in self.operating_system: - return os.path.join(self.PATH, "tools/chromedriver/chromedriver-windows.exe") - elif 'darwin' in self.operating_system: - if "arm" in platform.processor().lower(): - return os.path.join(self.PATH, "tools/chromedriver/chromedriver-mac-m1") - else: - return os.path.join(self.PATH, "tools/chromedriver/chromedriver-mac-intel") - else: - raise ValueError(f"Nicht unterstütztes Betriebssystem {self.operating_system}") - def get_chrome_options(self, headless: bool): chrome_options = uc.ChromeOptions() # deaktiviere Selenium Logging - chrome_options.add_argument('disable-infobars') + chrome_options.add_argument('--disable-infobars') # TODO: according to the annotations, second param should be a dict # FIXME invalid argument: cannot parse capability: goog:chromeOptions @@ -294,14 +278,19 @@ def get_chrome_options(self, headless: bool): chromebin_from_env = os.getenv("VACCIPY_CHROME_BIN") if chromebin_from_env: - chrome_options.binary_location = os.getenv("VACCIPY_CHROME_BIN") + # check for env variable with chromium binary path + chrome_options.binary_location = chromebin_from_env + elif check_chromium(): + # check for local installed chromium and set as binary executable + chrome_options.binary_location = str(chromium_executable()) chrome_options.headless = headless return chrome_options def get_chromedriver(self, headless: bool) -> WebDriver: - return uc.Chrome(options=self.get_chrome_options(headless)) + return uc.Chrome(executable_path=self.get_chromedriver_path(), + options=self.get_chrome_options(headless)) def driver_enter_code(self, driver: WebDriver, impfzentrum: Dict, code: str): """ @@ -1022,8 +1011,8 @@ def undetected_selenium_code_anfordern(self, mail: str, telefonnummer: str, driver.execute_script( 'window.sessionStorage.setItem("ets-session-its-cv-quick-check",\'' + ets_session_its_cv_quick_check + '\');') - self.log.info( - "\"ets-session-its-cv-quick-check\" Key:Value zum sessionStorage hinzugefügt.") + # self.log.info( + # "\"ets-session-its-cv-quick-check\" Key:Value zum sessionStorage hinzugefügt.") # Durch ets-session-its-cv-quick-check im SessionStorage kann direkt der Check # aufgerufen werden @@ -1271,7 +1260,7 @@ def terminsuche(codes: list, plz_impfzentren: list, kontakt: dict, # Einmal Chrome starten, um früh einen Fehler zu erzeugen, falls die # erforderliche Software nicht installiert ist. - its.log.info("Teste Chromedriver") + its.log.info("Prüfen von Chromium und Chromedriver") its.get_chromedriver(headless=True).quit() for plz_impfzentrum in cycle(plz_impfzentren): diff --git a/tools/utils.py b/tools/utils.py index 554d926f..e4e2f276 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -2,8 +2,6 @@ import time import traceback import random -import json -import sys from json import JSONDecodeError from pathlib import Path from threading import Thread From 9454675b5451ff20ef03567f538ace5f09661f6f Mon Sep 17 00:00:00 2001 From: iamnotturner Date: Tue, 22 Jun 2021 00:38:50 +0200 Subject: [PATCH 2/3] option 3: set environment variables --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 3141c45f..b1cab410 100755 --- a/main.py +++ b/main.py @@ -571,10 +571,12 @@ def main(): print() except TypeError as exc: if str(exc) == "expected str, bytes or os.PathLike object, not NoneType": - print("\nChromium nicht gefunden. Zwei Möglichkeiten zur Problembehebung:\n" + print("\nChromium nicht gefunden. Drei Möglichkeiten zur Problembehebung:\n" "1) Google Chrome installieren: https://www.google.com/intl/de_de/chrome/\n" "2) Chromium über das Vaccipy-Menü installieren: " - "'[3] Eigene Chromium Instanz im Vaccipy Ordner installieren'\n") + "'[3] Eigene Chromium Instanz im Vaccipy Ordner installieren'\n" + "3) Pfad für Chromium und Chromedriver über Umgebungsvariablen festlegen: " + "VACCIPY_CHROME_BIN (Chromium) und VACCIPY_CHROMEDRIVER (Chromedriver)\n") else: print(f"\nUnbekannter TypeError:\n{str(exc)}\n") except Exception as exc: From 8d9593cdf8840c06ea299977df43b23cef17e739 Mon Sep 17 00:00:00 2001 From: iamnotturner Date: Tue, 22 Jun 2021 12:06:08 +0200 Subject: [PATCH 3/3] returning webdriver exectuable as a string --- tools/its.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/its.py b/tools/its.py index d2269e3a..504cbef2 100644 --- a/tools/its.py +++ b/tools/its.py @@ -254,7 +254,7 @@ def get_chromedriver_path(self): if chromedriver_from_env: return chromedriver_from_env if check_webdriver(): - return webdriver_executable() + return str(webdriver_executable()) def get_chrome_options(self, headless: bool): chrome_options = uc.ChromeOptions()