BugFix importCSV

main
Cemal Odabasioglu 2023-12-06 10:30:10 +01:00
parent 4caef75230
commit 7806821abc
1 changed files with 31 additions and 27 deletions

View File

@ -28,7 +28,6 @@ import kotlinx.serialization.json.put
import java.io.File
import java.io.FileWriter
import java.io.IOException
import kotlinx.serialization.json.Json
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.JsonObject
@ -211,11 +210,11 @@ fun App() {
fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
val glossary = readJsonFile(jsonFilePath)
val csvContent = buildString {
appendLine("nom,description,contextePrincipal,contexte2,lieA,synonyme,antonyme")
appendLine("Mot;Description;Contexte principal;Contexte 2;Lié à;Synonyme;Antonyme;")
glossary.forEach { entry ->
appendLine(
"${entry["nom"]},${entry["description"]},${entry["contextePrincipal"]}," +
"${entry["contexte2"]},${entry["lieA"]},${entry["synonyme"]},${entry["antonyme"]}"
"${entry["nom"]};${entry["description"]};${entry["contextePrincipal"]};" +
"${entry["contexte2"]};${entry["lieA"]};${entry["synonyme"]};${entry["antonyme"]}"
)
}
}
@ -245,7 +244,10 @@ fun importCSV(cheminFichier: String) {
val dataLines = lines.drop(1)
dataLines.forEach { line ->
val values = line.split(";")
// Check if the line is not empty or blank
if (line.isNotBlank()) {
val values = line.replace("\r", "").replace("\n", "").split(";")
values.forEach { value ->
println(value)
}
@ -272,6 +274,8 @@ fun importCSV(cheminFichier: String) {
ajouterMotAuGlossaire(nouveauMot)
}
}
}
fun verifierChampsRequis(mot: Map<String, String>): Boolean {