Fix duplications of data, sort query list, visual improvements

This commit is contained in:
Guntis Smaukstelis
2023-05-21 13:26:17 +03:00
parent 040672d6e0
commit 8b3f97bb96
8 changed files with 15 additions and 21 deletions
+3 -10
View File
@@ -22,10 +22,11 @@ class DBService(log: Logger[IO]) {
private val dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
private val dataPath = "./data"
private def readFile(fileName: String): IO[List[String]] = {
// takes only first 34 lines of data as rest after 'Zosēni' is duplicated
def readFile(fileName: String): IO[List[String]] = {
val file = new File(dataPath, fileName)
val sourceResource = Resource.fromAutoCloseable(IO(Source.fromFile(file)))
sourceResource.use(source => IO(source.getLines().toList)).handleErrorWith(_ => IO.pure(List.empty))
sourceResource.use(source => IO(source.getLines().take(34).toList)).handleErrorWith(_ => IO.pure(List.empty))
}
private def readFileNames(path: String): IO[List[String]] =
@@ -82,12 +83,4 @@ class DBService(log: Logger[IO]) {
val dateStr: String = date.format(formatter)
readFileNames(dataPath).map(_.filter(_.startsWith(dateStr)).sorted)
}
def getFileContent(fileName: String): IO[String] = {
val file = new File(dataPath, fileName)
val sourceResource = Resource.fromAutoCloseable(IO(Source.fromFile(file)))
sourceResource.use(source => IO(source.getLines().mkString("<br/>\n"))).handleErrorWith { error =>
IO(println(s"Failed to read file: $error")) *> IO.pure("")
}
}
}