diff --git a/.gitignore b/.gitignore index e7fbf88..10ba534 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,7 @@ build/ !**/src/test/**/build/ ### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ +.idea *.iws *.iml *.ipr @@ -44,4 +41,5 @@ bin/ ### Mac OS ### .DS_Store -offers.md \ No newline at end of file +offers.md +rooms-scanned.txt \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e98f2e1 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Kamer Zoeken + +## Running + +If you want a command that just downloads, compiles and runs everything, run this: (Assumes you run Linux. It might work on Windows. no guarantees though.) + +```sh +git clone https://github.com/KoenDR06/KamerZoeken +cd KamerZoeken + +./gradlew build +java -jar build/libs/KamerZoeken-1.0.0.jar +``` \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 39c8cee..905758a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,17 +1,17 @@ plugins { kotlin("jvm") version "2.1.20" kotlin("plugin.serialization") version "2.1.21" + application } group = "me.koendev" -version = "1.0-SNAPSHOT" +version = "1.0.0" repositories { mavenCentral() } dependencies { - implementation(files("../Utils-latest.jar")) implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") implementation("de.thelooter:toml4j:0.8.1") } @@ -21,4 +21,24 @@ tasks.test { } kotlin { jvmToolchain(21) +} + +application.mainClass = "me.koendev.MainKt" + +tasks.withType { + // Otherwise you'll get a "No main manifest attribute" error + manifest { + attributes["Main-Class"] = "me.koendev.MainKt" + } + + // To avoid the duplicate handling strategy error + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + // To add all of the dependencies otherwise a "NoClassDefFoundError" error + from(sourceSets.main.get().output) + + dependsOn(configurations.runtimeClasspath) + from({ + configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) } + }) } \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 2e6697f..9282640 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -9,8 +9,16 @@ data class ReactableOffer( ) fun main() { + val inputFile = File("rooms-scanned.txt") + + val roomsFound = if (inputFile.exists()) inputFile.readLines() else listOf() + val rooms = getRooms().filter { room -> - room.unitType == config.general.unitType + room.unitType == config.general.unitType && room.wocasId !in roomsFound + } + if (rooms.isEmpty()) { + println("No suitable offers were found, quitting.") + return } val offers = getOffers(rooms.map { it.wocasId }).offers.filter { offer -> offer.adres[0].plaats !in listOf( @@ -62,12 +70,14 @@ fun main() { str.append("| Roken | ${if (it.floor.floorInfo.smokingAllowed) "✅ Mag" else "❌ Mag niet"} |\n") str.append("| Huisdieren | ${if (it.floor.floorInfo.petsAllowed) "✅ Mogen" else "❌ Mogen niet"} |\n") + str.append("| Reacties | ${it.floor.applicantCount} al gereageerd.") str.append("\n") - str.append("### Message: \n\n${it.floor.floorInfo.description}\n") + str.append("### Message: \n\n${it.floor.floorInfo.description ?: "Deze pannekoeken hebben geen bericht achtergelaten"}\n") str.append("\n\n") } out.writeText(str.toString()) + inputFile.writeText(roomsFound.joinToString("\n") + rooms.joinToString("\n") { it.wocasId }) println("${coupled.size} offers found, wrote to $fileName") } diff --git a/src/main/kotlin/getFloorInfo.kt b/src/main/kotlin/getFloorInfo.kt index c6d4a82..81fb01c 100644 --- a/src/main/kotlin/getFloorInfo.kt +++ b/src/main/kotlin/getFloorInfo.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.json.Json @Serializable data class FloorInfo( @SerialName("WocasId") val wocasId: String, - @SerialName("Description") val description: String, + @SerialName("Description") val description: String?, @SerialName("HospiteerDate") val hospiteerDate: String?, @SerialName("PreferenceSmokingAllowed") val smokingAllowed: Boolean, @SerialName("PreferencePetsAllowed") val petsAllowed: Boolean, diff --git a/src/main/kotlin/getOffers.kt b/src/main/kotlin/getOffers.kt index b3661e7..a6f4982 100644 --- a/src/main/kotlin/getOffers.kt +++ b/src/main/kotlin/getOffers.kt @@ -3,9 +3,6 @@ package me.koendev import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json -import me.koendev.utils.println -import java.net.http.HttpClient -import java.net.http.HttpResponse @Serializable data class Offers(