From d79053158364f46075d33e816052129456730612 Mon Sep 17 00:00:00 2001 From: KoenDR06 Date: Tue, 2 Sep 2025 20:28:20 +0200 Subject: [PATCH] removed deprecation warning and cleaned up code --- README.md | 8 +++----- config.toml | 2 +- sample.env | 3 ++- src/main/kotlin/Main.kt | 26 ++++++++++---------------- src/main/kotlin/TOML.kt | 4 ++-- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1babf6e..8cddc04 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,10 @@ If you want a command that just downloads, compiles and runs everything, run thi ```sh git clone https://github.com/KoenDR06/KamerZoeken cd KamerZoeken - ``` -Then, set your preferences in [config.toml](config.toml). After you have done this, run the following script: +Then, set your preferences in `[config.toml](config.toml)` and set your credentials in `.env` (you can find what secrets are needed in `[sample.env](sample.env)`). After you have done this, you are ready to run the script using: ```sh -./gradlew build -java -jar build/libs/KamerZoeken-1.0.0.jar -``` \ No newline at end of file +java -jar KamerZoeken-1.0.0.jar +``` diff --git a/config.toml b/config.toml index e50df5d..ef45bb8 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,6 @@ [general] unitType = "Kamer" # Kamer of Woning -allowZeist = true # Of je ook in Zeist wil zoeken +cities = ["ZEIST", "UTRECHT"] # Steden om in te zoeken smoking = -1 # 0: geen voorkeur, -1: ik wil dat er niet gerookt mag worden, 1: Ik wil dat er gerookt mag worden pets = 0 # 0: geen voorkeur, -1: ik wil dat er geen huisdieren mogen, 1: Ik wil dat huisdieren mogen diff --git a/sample.env b/sample.env index b2dd23a..4793ec5 100644 --- a/sample.env +++ b/sample.env @@ -1 +1,2 @@ -AUTH= \ No newline at end of file +EMAIL=test@example.com +PASSWORD="123456789" diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index bc530f3..2c43776 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -16,9 +16,10 @@ data class ReactableOffer( ) fun main() { + print("Authenticating") val sessionToken = auth() - print("Getting rooms") + print("\rGetting rooms ") val rooms = getRooms().filter { room -> room.unitType == config.general.unitType } @@ -28,12 +29,9 @@ fun main() { } val offers = getOffers(rooms.map { it.wocasId }).offers.filter { offer -> - offer.adres[0].plaats in listOf( - "UTRECHT", - ) + if (config.general.allowZeist) "ZEIST" else "" + offer.adres[0].plaats in config.general.cities } - print("\rFiltering on personal filters") var index = 0 val coupled = rooms.mapNotNull { room -> val offer: Offer? = offers.find { room.wocasId.toInt() == it.eenheidNummer.toInt() } @@ -43,11 +41,6 @@ fun main() { }.filter { val gender = it.floor.floorInfo.genderPreference - val date = it.room.expireBy.take(10) - val date1 = LocalDate.now() - val date2 = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")) - val daysLeft = ChronoUnit.DAYS.between(date1, date2) - val smoking = it.floor.floorInfo.smokingAllowed ?: true val pets = it.floor.floorInfo.petsAllowed ?: false @@ -57,9 +50,13 @@ fun main() { ((config.general.smoking == -1 && !smoking) || (config.general.smoking == 1 && smoking) || config.general.smoking == 0) && - ((config.general.pets == -1 && !pets) || (config.general.pets == 1 && pets) || config.general.pets == 0) && + ((config.general.pets == -1 && !pets) || (config.general.pets == 1 && pets) || config.general.pets == 0) + }.sortedBy { + val date = it.room.expireBy.take(10) + val date1 = LocalDate.now() + val date2 = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")) - daysLeft == 0L + ChronoUnit.DAYS.between(date1, date2) } val fileName = "offers.md" @@ -71,7 +68,7 @@ fun main() { coupled.forEach { val address = it.offer.adres[0] - str.append("## [${address.straatnaam} ${address.nummer}, ${address.plaats.lowercase().capitalize()}](https://sshxl.nl/nl/aanbod/${it.room.flowId}-${address.straatnaam.lowercase().replace(" ", "-")})\n") + str.append("## [${address.straatnaam} ${address.nummer}, ${address.plaats.lowercase().replaceFirstChar { if (it.isLowerCase()) it - 32 else it }}](https://sshxl.nl/nl/aanbod/${it.room.flowId}-${address.straatnaam.lowercase().replace(" ", "-")})\n") str.append("\n| Categorie | Waarde |\n") str.append("|-------------|--------------------|\n") @@ -99,9 +96,6 @@ fun main() { str.append("\n") - val etage = getEtage(it.offer.assSubjectPersk.first { it.pkHeeftAsp == 52.0 }.waarde!!) - - if (etage != null) str.append("![Foto](${etage.photos[0].etagePhoto[0].url})\n\n") str.append("### Message: \n\n${it.floor.floorInfo.description ?: "Deze pannekoeken hebben geen bericht achtergelaten"}\n") str.append("\n\n") diff --git a/src/main/kotlin/TOML.kt b/src/main/kotlin/TOML.kt index 83b1195..9ed4d57 100644 --- a/src/main/kotlin/TOML.kt +++ b/src/main/kotlin/TOML.kt @@ -5,7 +5,7 @@ import java.io.File data class GeneralConfig( val unitType: String, - val allowZeist: Boolean, + val cities: List, val smoking: Int, val pets: Int ) @@ -21,4 +21,4 @@ data class Config( val gender: GenderConfig, ) -val config: Config = Toml().read(File("config.toml")).to(Config::class.java) \ No newline at end of file +val config: Config = Toml().read(File("config.toml")).to(Config::class.java)