Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #131 from Z-Jais/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Ziedelth authored Sep 8, 2023
2 parents 6b37161 + 34725a0 commit 28d2687
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget>
<kotlin.version>1.9.0</kotlin.version>
<kotlin.version>1.9.10</kotlin.version>
<mainClass>fr.jais.scraper.ScraperKt</mainClass>
<junit-jupiter.version>5.10.0</junit-jupiter.version>
</properties>
Expand Down
47 changes: 2 additions & 45 deletions src/main/kotlin/fr/jais/scraper/jobs/AyaneJob.kt
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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
Expand Down Expand Up @@ -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]}"
}

Expand All @@ -68,51 +62,14 @@ 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")
}

Logger.info("Ayane is released!")
}

private fun post(body: String): HttpResponse<String> {
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)
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/fr/jais/scraper/utils/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,12 @@ object API {
Logger.log(Level.SEVERE, "Error saving episodes", e)
}
}

fun saveAyane(message: String, images: List<String>) {
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)
}
}
}
13 changes: 8 additions & 5 deletions src/main/kotlin/fr/jais/scraper/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ internal class CrunchyrollEpisodeWithNoImagePreviewIsNotScrap {
</rss>
""".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())
Expand Down

0 comments on commit 28d2687

Please sign in to comment.