Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
feat(local-chromium): replacing chromedriver binaries with google chr…
Browse files Browse the repository at this point in the history
…ome or custom chromium installation (#509)

* disabled local chromedriver, replaced with google chrome or custom chromium installation

* option 3: set environment variables

* returning webdriver exectuable as a string
  • Loading branch information
timreibe committed Jun 22, 2021
1 parent add1e07 commit 8df62f8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
15 changes: 15 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -564,6 +569,16 @@ 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. 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) 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:
print(f"\nFehler:\n{str(exc)}\n")

Expand Down
39 changes: 14 additions & 25 deletions tools/its.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, \
Expand Down Expand Up @@ -254,29 +254,13 @@ def get_chromedriver_path(self):
if chromedriver_from_env:
return chromedriver_from_env
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}")
return str(webdriver_executable())

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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8df62f8

Please sign in to comment.