From c08ac78e2d6eb0206806c35623f6914fc0bcd478 Mon Sep 17 00:00:00 2001 From: timoknapp Date: Tue, 11 May 2021 16:19:09 +0200 Subject: [PATCH] feat: provide distinct server code with placement code --- README.md | 4 ++-- src/main/kotlin/de/tfr/impf/ReportJob.kt | 6 +++++- src/main/kotlin/de/tfr/impf/config/Config.kt | 6 ++++-- src/main/kotlin/de/tfr/impf/page/LocationPage.kt | 16 ++++++++++++++++ src/main/resources/config.properties | 4 ++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 64b90c6..36e039c 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,8 @@ Edit these settings before the first run. A missing boolean property will be tre ```properties mainPageUrl = https://www.impfterminservice.de/impftermine -# Comma separated list of locations. Optional, if you already have a placement code just add it in square brackets after the place. -locations = 69124 Heidelberg[XXXX-XXXX-XXXX],76137 Karlsruhe +# Comma separated list of locations. Optional, if you already have a placement code just add it in square brackets after the place. Since placement codes are not related to locations but to servers you can furthermore optionally specify the related server code next to the placement code in parentheses. The server code can be found in the URL e.g. "001-iz.impfterminservice.de" -> server code == "001". +locations = 69124 Heidelberg[XXXX-XXXX-XXXX](XXX),76137 Karlsruhe # Your age. Used in age verification field. personAge = 42 diff --git a/src/main/kotlin/de/tfr/impf/ReportJob.kt b/src/main/kotlin/de/tfr/impf/ReportJob.kt index d6f8683..791bbb8 100644 --- a/src/main/kotlin/de/tfr/impf/ReportJob.kt +++ b/src/main/kotlin/de/tfr/impf/ReportJob.kt @@ -76,8 +76,12 @@ class ReportJob { locationPage: LocationPage, location: Config.Location ) { - locationPage.confirmClaim() val code = location.placementCode + val serverCode = location.serverCode + if (serverCode != null) { + locationPage.switchToDifferentServer(serverCode) + } + locationPage.confirmClaim() if (code != null) { locationPage.enterCodeSegment0(code) locationPage.searchForFreeDate() diff --git a/src/main/kotlin/de/tfr/impf/config/Config.kt b/src/main/kotlin/de/tfr/impf/config/Config.kt index 4a2d81c..15fc1b5 100644 --- a/src/main/kotlin/de/tfr/impf/config/Config.kt +++ b/src/main/kotlin/de/tfr/impf/config/Config.kt @@ -90,12 +90,14 @@ object Config : KProperties() { */ private fun parseLocation(locationStatement: String): Location { val placementCode = locationStatement.substringAfter("[", "").substringBefore("]", "").ifEmpty { null } + val serverCode = locationStatement.substringAfter("(","").substringBefore(")", "").ifEmpty { null } val name = locationStatement.substringBefore("[") - return Location(name, placementCode) + return Location(name, placementCode, serverCode) } - class Location(val name: String, val placementCode: String?) { + class Location(val name: String, val placementCode: String?, val serverCode: String?) { fun hasCode() = placementCode != null + fun hasServerCode() = serverCode != null private fun getCodeSegment(index: Int): String = (placementCode?.split("-")?.get(index)).orEmpty() fun getCodeSegment0(): String = getCodeSegment(0) diff --git a/src/main/kotlin/de/tfr/impf/page/LocationPage.kt b/src/main/kotlin/de/tfr/impf/page/LocationPage.kt index 04856af..3ebc7b1 100644 --- a/src/main/kotlin/de/tfr/impf/page/LocationPage.kt +++ b/src/main/kotlin/de/tfr/impf/page/LocationPage.kt @@ -1,10 +1,13 @@ package de.tfr.impf.page +import mu.KotlinLogging import org.openqa.selenium.WebDriver import org.openqa.selenium.WebElement class LocationPage(driver: WebDriver) : AbstractPage(driver) { + val log = KotlinLogging.logger("LocationPage") + fun title(): WebElement? = findAnyBy("//h1") override fun isDisplayed() = title()?.text == "Wurde Ihr Anspruch auf eine Corona-Schutzimpfung bereits geprüft?" @@ -73,4 +76,17 @@ class LocationPage(driver: WebDriver) : AbstractPage(driver) { fun hasVacError(): Boolean = findAll("//span[contains(@class, 'text-pre-wrap') and contains(text(), 'Fehler')]").isNotEmpty() + fun switchToDifferentServer(serverCode: String) { + if (!driver.currentUrl.contains("$serverCode-iz")) { + val url = driver.currentUrl + val newUrl = if (url.startsWith("https://")) { + url.replaceRange(8, 11, serverCode) + } else { + url.replaceRange(0, 2, serverCode) + } + log.debug("Redirect to distinct IZ Server. From: $url to: $newUrl") + driver.get(newUrl) + } + } + } \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 5c69883..104267c 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -1,6 +1,6 @@ mainPageUrl = https://www.impfterminservice.de/impftermine -# Comma separated list of locations. Optional, if you already have a placement code just add it in square brackets after the place. -locations = 69124 Heidelberg[XXXX-XXXX-XXXX],76137 Karlsruhe +# Comma separated list of locations. Optional, if you already have a placement code just add it in square brackets after the place. Furthermore you can optionally specify the related server code next to the placement code in parentheses (can be found in the URL e.g. "001-iz.impfterminservice.de -> server code == 001). +locations = 69124 Heidelberg[XXXX-XXXX-XXXX](XXX),76137 Karlsruhe # Your age. Used in age verification field. personAge = 42