Better properties handling.

This commit is contained in:
Chris Hodges 2023-12-09 11:47:09 +01:00
parent fb3a5ce5d2
commit 56fcbfe165

View File

@ -12,19 +12,15 @@ import java.nio.file.Paths
import java.time.LocalDate import java.time.LocalDate
import java.time.Month import java.time.Month
import java.time.ZoneId import java.time.ZoneId
import java.util.*
fun main() { fun main() {
var cookie = "<insert your session cookie here or store in gradle.properties>" var cookie = "<insert your session cookie here or store in gradle.properties>"
if (Files.exists(Paths.get("gradle.properties"))) { if (Files.exists(Paths.get("gradle.properties"))) {
val cookieFromProps = Files.readAllLines(Paths.get("gradle.properties")) val props = Properties()
.map { it.split("=") } props.load(Files.newBufferedReader(Paths.get("gradle.properties")))
.filter { it.size == 2 } cookie = props.getProperty("cookie", cookie)
.filter { it[0] == "cookie" }
.map { it[1] }.firstOrNull()
if (cookieFromProps != null) {
cookie = cookieFromProps
}
} }
val downloader = Downloader(2023, "aoc2023", cookie) val downloader = Downloader(2023, "aoc2023", cookie)