diff --git a/pom.xml b/pom.xml index baa6040..3158d80 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ UTF-8 official 11 - 1.9.0 + 1.9.10 fr.jais.scraper.ScraperKt 5.10.0 diff --git a/src/main/kotlin/fr/jais/scraper/jobs/AyaneJob.kt b/src/main/kotlin/fr/jais/scraper/jobs/AyaneJob.kt index 2c46d07..5ae99ff 100644 --- a/src/main/kotlin/fr/jais/scraper/jobs/AyaneJob.kt +++ b/src/main/kotlin/fr/jais/scraper/jobs/AyaneJob.kt @@ -1,7 +1,5 @@ package fr.jais.scraper.jobs -import com.google.gson.Gson -import com.google.gson.JsonObject import com.microsoft.playwright.Playwright import com.mortennobel.imagescaling.ResampleOp import fr.jais.scraper.utils.* @@ -13,11 +11,7 @@ import java.awt.RenderingHints import java.awt.image.BufferedImage import java.io.ByteArrayOutputStream import java.io.File -import java.net.URI import java.net.URL -import java.net.http.HttpClient -import java.net.http.HttpRequest -import java.net.http.HttpResponse import java.time.LocalDate import java.time.format.DateTimeFormatter import java.time.format.TextStyle @@ -54,7 +48,7 @@ class AyaneJob : Job { episodes.forEach { string += "\n#${ - it.first.name.split(":").first().capitalizeWords().onlyLettersAndDigits() + it.first.name.split(":", ",", "-").first().capitalizeWords().onlyLettersAndDigits() } EP${it.second.split(" ")[1]}" } @@ -68,35 +62,7 @@ Bonne journée ! 😊""" imageToBase64(generateImage(font, chunked, backgroundImage, adnImage, crunchyrollImage, netflixImage)) } - val fileConf = File(folder, "conf.json") - - if (!fileConf.exists()) { - fileConf.createNewFile() - fileConf.writeText("{}") - Logger.warning("ayane/conf.json file created, please fill it") - return - } - - val conf = Gson().fromJson(fileConf.readText(), JsonObject::class.java) - requireNotNull(conf["TWITTER_EMAIL"]) { "TWITTER_EMAIL is not defined in .env file" } - requireNotNull(conf["TWITTER_PSEUDO"]) { "TWITTER_PSEUDO is not defined in .env file" } - requireNotNull(conf["TWITTER_PASSWORD"]) { "TWITTER_PASSWORD is not defined in .env file" } - - post( - Gson().toJson( - mapOf( - "email" to conf["TWITTER_EMAIL"].asString, - "pseudo" to conf["TWITTER_PSEUDO"].asString, - "password" to conf["TWITTER_PASSWORD"].asString, - "tweets" to listOf( - mapOf( - "message" to string, - "images" to images - ) - ) - ) - ) - ) + API.saveAyane(string, images) } catch (e: Exception) { println("Error: $e") } @@ -104,15 +70,6 @@ Bonne journée ! 😊""" Logger.info("Ayane is released!") } - private fun post(body: String): HttpResponse { - val request = HttpRequest.newBuilder() - .uri(URI.create("http://192.168.1.179:8082/")) - .header("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(body)) - .build() - return HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()) - } - private fun imageToBase64(image: BufferedImage): String { val outputStream = ByteArrayOutputStream() ImageIO.write(image, "png", outputStream) diff --git a/src/main/kotlin/fr/jais/scraper/utils/API.kt b/src/main/kotlin/fr/jais/scraper/utils/API.kt index f647880..a9792ee 100644 --- a/src/main/kotlin/fr/jais/scraper/utils/API.kt +++ b/src/main/kotlin/fr/jais/scraper/utils/API.kt @@ -159,4 +159,12 @@ object API { Logger.log(Level.SEVERE, "Error saving episodes", e) } } + + fun saveAyane(message: String, images: List) { + try { + post("${URL}ayane", Const.gson.toJson(mapOf("message" to message, "images" to images))) + } catch (e: Exception) { + Logger.log(Level.SEVERE, "Error saving episodes", e) + } + } } diff --git a/src/main/kotlin/fr/jais/scraper/utils/Extensions.kt b/src/main/kotlin/fr/jais/scraper/utils/Extensions.kt index 3628d75..7b408bc 100644 --- a/src/main/kotlin/fr/jais/scraper/utils/Extensions.kt +++ b/src/main/kotlin/fr/jais/scraper/utils/Extensions.kt @@ -30,11 +30,14 @@ fun String.toMD5(): String { return BigInteger(1, md.digest(this.toByteArray())).toString(16).padStart(32, '0') } -fun String.capitalizeWords(): String = split(" ", "-").joinToString(" ") { it.replaceFirstChar { - if (it.isLowerCase()) it.titlecase( - Locale.getDefault() - ) else it.toString() -} } +fun String.capitalizeWords(): String = split(" ", "-").joinToString(" ") { + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase( + Locale.getDefault() + ) else it.toString() + } +} + fun String.onlyLettersAndDigits(): String = this.filter { it.isLetterOrDigit() } fun BufferedImage.opacity(opacity: Float): BufferedImage { diff --git a/src/test/java/fr/jais/scraper/bugs/CrunchyrollEpisodeWithNoImagePreviewIsNotScrap.kt b/src/test/java/fr/jais/scraper/bugs/CrunchyrollEpisodeWithNoImagePreviewIsNotScrap.kt index 9e1665b..c3c117e 100644 --- a/src/test/java/fr/jais/scraper/bugs/CrunchyrollEpisodeWithNoImagePreviewIsNotScrap.kt +++ b/src/test/java/fr/jais/scraper/bugs/CrunchyrollEpisodeWithNoImagePreviewIsNotScrap.kt @@ -47,7 +47,8 @@ internal class CrunchyrollEpisodeWithNoImagePreviewIsNotScrap { """.trimIndent() - platform.simulcasts[country] = mutableSetOf("Je me fais isekai pour la deuxième fois... Ça commence à faire beaucoup.".lowercase()) + platform.simulcasts[country] = + mutableSetOf("Je me fais isekai pour la deuxième fois... Ça commence à faire beaucoup.".lowercase()) val jsonEpisode = platform.xmlToJson(xmlEpisode)!!.get(0).asJsonObject println(jsonEpisode) platform.converter.convertEpisode(country, jsonEpisode, emptyList())