Skip to content

Commit

Permalink
Merge pull request #30 from timoknapp/master
Browse files Browse the repository at this point in the history
feat: provide distinct server code with placement code
  • Loading branch information
TobseF committed May 11, 2021
2 parents a282752 + c08ac78 commit 3ac48d4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/de/tfr/impf/ReportJob.kt
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/de/tfr/impf/config/Config.kt
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions 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?"
Expand Down Expand Up @@ -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)
}
}

}
4 changes: 2 additions & 2 deletions 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
Expand Down

0 comments on commit 3ac48d4

Please sign in to comment.