diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ffc9449..23c90d3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -58,6 +58,8 @@ dependencies { implementation("joda-time:joda-time:2.10.10") implementation("com.beust:klaxon:5.5") + + implementation("com.natpryce:konfig:1.6.10.0") } application { diff --git a/app/src/main/kotlin/xyz/etztech/stonks/App.kt b/app/src/main/kotlin/xyz/etztech/stonks/App.kt index e46c04f..e195e91 100644 --- a/app/src/main/kotlin/xyz/etztech/stonks/App.kt +++ b/app/src/main/kotlin/xyz/etztech/stonks/App.kt @@ -1,5 +1,8 @@ package xyz.etztech.stonks +import com.natpryce.konfig.* +import java.io.FileInputStream +import java.util.* import kotlinx.coroutines.* import org.h2.tools.Server import org.jetbrains.exposed.exceptions.ExposedSQLException @@ -14,11 +17,19 @@ fun main() = runBlocking { println("Starting Stonks...") - val databaseBaseDir = "./databases" - val databaseName = "statistics" - val h2StartWebServer = true - val h2tWebServerPort = 8082 - val h2TcpServerPort = 9092 + val fis = FileInputStream("./stonks.config") + val config = Properties() + + config.load(fis) + + val databaseBaseDir = config.getProperty("databaseBaseDir") + val databaseName = config.getProperty("databaseName") + val h2StartWebServer = config.getProperty("h2StartWebServer").toBoolean() + val h2tWebServerPort = config.getProperty("h2tWebServerPort").toInt() + val h2TcpServerPort = config.getProperty("h2TcpServerPort").toInt() + val apiServerPort = config.getProperty("apiServerPort").toInt() + val periodicFetchingInterval = config.getProperty("periodicFetchingInterval").toLong() + val minecraftStatsFolder = config.getProperty("minecraftStatsFolder") val database = initH2Server( @@ -28,13 +39,8 @@ fun main() = h2StartWebServer, h2tWebServerPort) - val apiServerPort = 7000 - initApiServer(apiServerPort, database) - val periodicFetchingInterval = 15 * 60 * 1000L - val minecraftStatsFolder = "../test_data" - initPeriodicFetching(periodicFetchingInterval, minecraftStatsFolder, database) delay(60 * 1000L) diff --git a/app/stonks.config b/app/stonks.config new file mode 100644 index 0000000..617d659 --- /dev/null +++ b/app/stonks.config @@ -0,0 +1,8 @@ +databaseBaseDir=./databases +databaseName=statistics +h2StartWebServer=true +h2tWebServerPort=8082 +h2TcpServerPort=9092 +apiServerPort=7000 +periodicFetchingInterval=900000 +minecraftStatsFolder=../test_data \ No newline at end of file