Some syntax changes before resuming project

This commit is contained in:
Matte23
2021-09-21 11:34:59 +02:00
parent 7bf5f83b4c
commit 387c1ea35b
5 changed files with 18 additions and 19 deletions

View File

@@ -31,13 +31,15 @@ actual class SpecificPorporatoServer actual constructor(private val porporatoSer
val list = ArrayList<Circular>()
for (i in 0 until htmlList.size) {
list.add(
porporatoServer.generateFromString(
htmlList[i].text(),
htmlList[i].attr("href"),
i.toLong()
)?.let {
list.add(
it
)
)
}
}
return list

View File

@@ -67,7 +67,6 @@ class CurieServer(ktorClient: HttpClient) : Server(ktorClient) {
return Pair(true, ServerAPI.Companion.Result.SUCCESS)
}
@OptIn(ExperimentalStdlibApi::class)
@Throws(IOException::class, CancellationException::class)
private suspend fun retrieveDataFromServer(): Response {
return ktorClient.get(ENDPOINT_URL)

View File

@@ -75,7 +75,6 @@ class PorporatoServer(ktorClient: HttpClient) : Server(ktorClient) {
return Pair(true, ServerAPI.Companion.Result.SUCCESS)
}
@OptIn(ExperimentalStdlibApi::class)
@Throws(IOException::class, CancellationException::class)
private suspend fun parsePage(url: String): List<Circular> {
val response = retrieveDataFromServer(url)
@@ -120,13 +119,12 @@ class PorporatoServer(ktorClient: HttpClient) : Server(ktorClient) {
}
}
@OptIn(ExperimentalStdlibApi::class)
@Throws(IOException::class, CancellationException::class)
private suspend fun retrieveDataFromServer(url: String): String {
return ktorClient.request<HttpResponse>(url).readText(Charsets.ISO_8859_1)
}
fun generateFromString(string: String, path: String, index: Long): Circular {
fun generateFromString(string: String, path: String, index: Long): Circular? {
val fullUrl = baseUrl + path
var title = string
@@ -152,7 +150,7 @@ class PorporatoServer(ktorClient: HttpClient) : Server(ktorClient) {
title = title.removeRange(dateMatcher.range)
.removeSuffix(" (pubb.: )")
Circular(id, serverID, title, fullUrl, fullUrl, dateMatcher.value.replace("-", "/"))
if (title != "") Circular(id, serverID, title, fullUrl, fullUrl, dateMatcher.value.replace("-", "/")) else null
} else {
Circular(id, serverID, title, fullUrl, fullUrl, "")
}

View File

@@ -59,7 +59,6 @@ abstract class GenericPreverServer(ktorClient: HttpClient) : Server(ktorClient)
}
}
@OptIn(ExperimentalStdlibApi::class)
@Throws(IOException::class, CancellationException::class)
private suspend fun parsePage(page: Int): List<Circular> {
val posts = retrievePageFromServer(page)
@@ -83,7 +82,6 @@ abstract class GenericPreverServer(ktorClient: HttpClient) : Server(ktorClient)
return Pair(true, ServerAPI.Companion.Result.SUCCESS)
}
@OptIn(ExperimentalStdlibApi::class)
@Throws(IOException::class, CancellationException::class)
private suspend fun retrievePageFromServer(page: Int): List<Post> {
return try {

View File

@@ -35,13 +35,15 @@ actual class SpecificPorporatoServer actual constructor(private val porporatoSer
return list
for (i in htmlList.indices) {
list.add(
porporatoServer.generateFromString(
htmlList[i].textContent,
htmlList[i].attributes.objectForKey("href").toString(),
i.toLong()
)?.let {
list.add(
it
)
)
}
}
return list