Parser accepts querying data, server reads from parser

This commit is contained in:
Guntis Smaukstelis
2023-04-18 17:18:45 +03:00
parent 260b6ef23a
commit 0e60f94835
6 changed files with 94 additions and 26 deletions
+2
View File
@@ -13,6 +13,7 @@ import java.nio.file.{Files, Paths}
import scala.concurrent.ExecutionContext.global
object FetchData extends IOApp.Simple {
// TODO wrap config in IO
private val config = ConfigFactory.load()
private val basicCredentials = BasicCredentials(config.getString("username"), config.getString("password"))
private val baseUrl = Uri.unsafeFromString(config.getString("url")) // 20220831_1330.csv
@@ -20,6 +21,7 @@ object FetchData extends IOApp.Simple {
def saveToFile(fileName: String, content: String): IO[Unit] = {
val path = Paths.get(s"data/$fileName")
// TODO redeemWith instead of flatMap
IO(Files.writeString(path, content)).attempt.flatMap {
case Right(_) => IO(println(s"write: $fileName"))
case Left(error) => IO(println(s"Write file '$fileName' failed with error: ${error.getMessage}"))
+1
View File
@@ -8,6 +8,7 @@ object FileName {
private val formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
def generateLastHour(): List[String] = {
// TODO IO.timer() IOTimer
val now = LocalDateTime.now
generate(now.minusHours(1), now)
}