diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..447b939f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git +.github +.idea +docs +images +specs +venv +.dockerignore +.gitignore +Dockerfile +docker-compose.yaml +FAQ.md +gui.py +impfzentren_gruppiert.md +LICENSE +README.md diff --git a/.env b/.env new file mode 100644 index 00000000..6d556158 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +VACCIPY_ARGUMENTS= +VACCIPY_CONTACT_ADDRESS_PATH=~/kontaktdaten.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 31214358..ace0893e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ -.idea/ -.vscode/ -__pycache__/ - -*.DS_Store - # log log/ @@ -11,11 +5,329 @@ log/ kontaktdaten.json zeitspanne.json -#building: -installer/ +# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,jetbrains+all,visualstudiocode,python +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,jetbrains+all,visualstudiocode,python + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class -# pyinstaller -# temporary building files: -build/ +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ dist/ +downloads/ +eggs/ +.eggs/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +# .env +.env/ +.venv/ +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# operating system-related files +# file properties cache/storage on macOS +*.DS_Store +# thumbnail cache on Windows +Thumbs.db + +# profiling data +.prof + + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,jetbrains+all,visualstudiocode,python + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e3713d48 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.9.5-buster + +WORKDIR vaccipy + +RUN apt-get update && apt-get install -y jq + +ADD . . + +RUN python -m pip install -r requirements.txt + +RUN chmod +x ./wait-for-google-chrome.sh + +ENTRYPOINT ./wait-for-google-chrome.sh python3 main.py search -f kontaktdaten.json -r diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..1aafb5e3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,21 @@ +version: "3.9" +services: + google-chrome: + environment: + # Necessary to allow connections other than from the local address. + - JAVA_OPTS=-Dwebdriver.chrome.whitelistedIps= + image: selenium/standalone-chrome:91.0 + ports: + - "4444:4444" + vaccipy: + build: . + # Arguments passed to vaccipy. + command: ${VACCIPY_ARGUMENTS} + environment: + - VACCIPY_CHROME_REMOTE_ADDRESS=http://google-chrome:4444/wd/hub + image: vaccipy + volumes: + - type: bind + read_only: true + source: ${VACCIPY_CONTACT_ADDRESS_PATH} + target: /vaccipy/kontaktdaten.json diff --git a/tools/its.py b/tools/its.py index d36db2b5..68371bf2 100644 --- a/tools/its.py +++ b/tools/its.py @@ -13,7 +13,7 @@ from selenium.webdriver import ActionChains -from selenium.webdriver import Chrome +from selenium.webdriver import Chrome, Remote from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC @@ -182,11 +182,8 @@ def get_chromedriver_path(self): def get_chromedriver(self, headless): chrome_options = Options() - - # deaktiviere Selenium Logging chrome_options.add_argument('disable-infobars') - chrome_options.add_experimental_option('useAutomationExtension', False) chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) @@ -204,7 +201,11 @@ def get_chromedriver(self, headless): chrome_options.headless = headless - return Chrome(self.get_chromedriver_path(), options=chrome_options) + chrome_remote_address = os.getenv("VACCIPY_CHROME_REMOTE_ADDRESS") + if chrome_remote_address: + return Remote(chrome_remote_address, options=chrome_options) + else: + return Chrome(self.get_chromedriver_path(), options=chrome_options) def driver_enter_code(self, driver, plz_impfzentrum): """ diff --git a/wait-for-google-chrome.sh b/wait-for-google-chrome.sh new file mode 100644 index 00000000..d16ac8ff --- /dev/null +++ b/wait-for-google-chrome.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Taken from https://github.com/SeleniumHQ/docker-selenium#using-a-bash-script-to-wait-for-the-grid. + +set -e + +cmd="$@" + +while ! curl -sSL "http://google-chrome:4444/wd/hub/status" 2>&1 \ + | jq -r '.value.ready' 2>&1 | grep "true" >/dev/null; do + echo 'Waiting for Google Chrome to start...' + sleep 1 +done + +exec $cmd