Add last announcement feature
This commit is contained in:
parent
e077867957
commit
8ffd7b0d35
11 changed files with 164 additions and 2 deletions
|
@ -38,6 +38,7 @@ public final class io/github/wulkanowy/sdk/scrapper/Scrapper {
|
|||
public final fun getKidsLessonPlan (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getKidsLuckyNumbers (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getKindergartenDiaryId ()I
|
||||
public final fun getLastAnnouncements (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getLastGrades (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getLastHomework (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getLastStudentLessons (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
|
@ -836,6 +837,23 @@ public final class io/github/wulkanowy/sdk/scrapper/home/GovernmentUnit$Companio
|
|||
public final fun serializer ()Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
public final class io/github/wulkanowy/sdk/scrapper/home/LastAnnouncement {
|
||||
public fun <init> (Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
|
||||
public final fun component1 ()Ljava/time/LocalDate;
|
||||
public final fun component2 ()Ljava/lang/String;
|
||||
public final fun component3 ()Ljava/lang/String;
|
||||
public final fun component4 ()Ljava/lang/String;
|
||||
public final fun copy (Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/scrapper/home/LastAnnouncement;
|
||||
public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/scrapper/home/LastAnnouncement;Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/scrapper/home/LastAnnouncement;
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public final fun getAuthor ()Ljava/lang/String;
|
||||
public final fun getContent ()Ljava/lang/String;
|
||||
public final fun getDate ()Ljava/time/LocalDate;
|
||||
public final fun getSubject ()Ljava/lang/String;
|
||||
public fun hashCode ()I
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class io/github/wulkanowy/sdk/scrapper/home/LuckyNumber {
|
||||
public fun <init> (Ljava/lang/String;Ljava/lang/String;I)V
|
||||
public final fun component1 ()Ljava/lang/String;
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.github.wulkanowy.sdk.scrapper.grades.GradesStatisticsPartial
|
|||
import io.github.wulkanowy.sdk.scrapper.grades.GradesStatisticsSemester
|
||||
import io.github.wulkanowy.sdk.scrapper.home.DirectorInformation
|
||||
import io.github.wulkanowy.sdk.scrapper.home.GovernmentUnit
|
||||
import io.github.wulkanowy.sdk.scrapper.home.LastAnnouncement
|
||||
import io.github.wulkanowy.sdk.scrapper.home.LuckyNumber
|
||||
import io.github.wulkanowy.sdk.scrapper.homework.Homework
|
||||
import io.github.wulkanowy.sdk.scrapper.login.LoginHelper
|
||||
|
@ -495,6 +496,8 @@ class Scrapper {
|
|||
|
||||
suspend fun getDirectorInformation(): List<DirectorInformation> = homepage.getDirectorInformation()
|
||||
|
||||
suspend fun getLastAnnouncements(): List<LastAnnouncement> = homepage.getLastAnnouncements()
|
||||
|
||||
suspend fun getSelfGovernments(): List<GovernmentUnit> = homepage.getSelfGovernments()
|
||||
|
||||
suspend fun getStudentThreats(): List<String> = homepage.getStudentThreats()
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.home
|
||||
|
||||
import java.time.LocalDate
|
||||
|
||||
data class LastAnnouncement(
|
||||
val date: LocalDate,
|
||||
val subject: String,
|
||||
val author: String,
|
||||
val content: String,
|
||||
)
|
|
@ -3,11 +3,12 @@ package io.github.wulkanowy.sdk.scrapper.repository
|
|||
import io.github.wulkanowy.sdk.scrapper.getScriptParam
|
||||
import io.github.wulkanowy.sdk.scrapper.home.DirectorInformation
|
||||
import io.github.wulkanowy.sdk.scrapper.home.GovernmentUnit
|
||||
import io.github.wulkanowy.sdk.scrapper.home.LastAnnouncement
|
||||
import io.github.wulkanowy.sdk.scrapper.home.LuckyNumber
|
||||
import io.github.wulkanowy.sdk.scrapper.interceptor.handleErrors
|
||||
import io.github.wulkanowy.sdk.scrapper.service.HomepageService
|
||||
import io.github.wulkanowy.sdk.scrapper.toDate
|
||||
import io.github.wulkanowy.sdk.scrapper.toLocalDate
|
||||
import java.time.LocalDate
|
||||
|
||||
internal class HomepageRepository(private val api: HomepageService) {
|
||||
|
||||
|
@ -27,7 +28,7 @@ internal class HomepageRepository(private val api: HomepageService) {
|
|||
return requireNotNull(res).flatMap { wrapper ->
|
||||
wrapper.content.map {
|
||||
DirectorInformation(
|
||||
date = it.name.substringBefore(" ").toDate("dd.MM.yyyy").toLocalDate(),
|
||||
date = it.name.substringBefore(" ").toLocalDate("dd.MM.yyyy"),
|
||||
subject = it.name.substringAfter(" "),
|
||||
content = it.data.orEmpty(),
|
||||
)
|
||||
|
@ -35,6 +36,20 @@ internal class HomepageRepository(private val api: HomepageService) {
|
|||
}.sortedBy { it.date }
|
||||
}
|
||||
|
||||
suspend fun getLastAnnouncements(): List<LastAnnouncement> {
|
||||
val res = api.getLastAnnouncements(getToken()).handleErrors().data
|
||||
return requireNotNull(res).flatMap { wrapper ->
|
||||
wrapper.content.map {
|
||||
LastAnnouncement(
|
||||
subject = it.name.trim(),
|
||||
date = it.symbol?.substringBefore(", ")?.toLocalDate("dd.MM.yyyy") ?: LocalDate.EPOCH,
|
||||
author = it.symbol?.substringAfter(", ").orEmpty(),
|
||||
content = it.data.orEmpty(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getSelfGovernments(): List<GovernmentUnit> {
|
||||
val res = api.getSelfGovernments(getToken()).handleErrors().data
|
||||
return requireNotNull(res)
|
||||
|
|
|
@ -17,6 +17,10 @@ internal interface HomepageService {
|
|||
@POST("Start.mvc/GetStudentDirectorInformations")
|
||||
suspend fun getDirectorInformation(@Field("permissions") token: String): ApiResponse<List<HomepageTileResponse>>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("Start.mvc/GetLastAnnouncements")
|
||||
suspend fun getLastAnnouncements(@Field("permissions") token: String): ApiResponse<List<HomepageTileResponse>>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("Start.mvc/GetSelfGovernments")
|
||||
suspend fun getSelfGovernments(@Field("permissions") token: String): ApiResponse<List<GovernmentUnit>>
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.github.wulkanowy.sdk.scrapper.home.LuckyNumber
|
|||
import io.github.wulkanowy.sdk.scrapper.repository.HomepageRepository
|
||||
import io.github.wulkanowy.sdk.scrapper.service.HomepageService
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
@ -40,6 +41,32 @@ class HomepageTest : BaseLocalTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getLastAnnouncements() = runTest {
|
||||
with(server) {
|
||||
enqueue("Index.html")
|
||||
enqueue("GetLastAnnouncements.json")
|
||||
start(3000)
|
||||
}
|
||||
|
||||
val infos = repo.getLastAnnouncements()
|
||||
assertEquals(2, infos.size)
|
||||
|
||||
with(infos[0]) {
|
||||
assertEquals(of(2024, 2, 27), date)
|
||||
assertEquals("Wydarzenia", subject)
|
||||
assertEquals("Jan kowalski", author)
|
||||
assertEquals("<p>W dniu 29 lutego 2024 r. uczniowie klasy 3d biorą udział w wyjściu na strzelnicę.</p>", content)
|
||||
}
|
||||
|
||||
with(infos[1]) {
|
||||
assertEquals(of(2023, 12, 5), date)
|
||||
assertEquals("Platformy", subject)
|
||||
assertEquals("Malwina Czerwieńska", author)
|
||||
assertEquals("<p>Platformy do wykorzystania dla uczniów w zakresie kompetencji cyfrowych:</p>", content)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSelfGovernments() {
|
||||
with(server) {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"data": [
|
||||
{
|
||||
"IkonkaNazwa": null,
|
||||
"Num": null,
|
||||
"Zawartosc": [
|
||||
{
|
||||
"IkonkaNazwa": null,
|
||||
"Num": null,
|
||||
"Zawartosc": [],
|
||||
"Rozszerzenie": false,
|
||||
"Nazwa": "Wydarzenia ",
|
||||
"Url": null,
|
||||
"Dane": "<p>W dniu 29 lutego 2024 r. uczniowie klasy 3d biorą udział w wyjściu na strzelnicę.</p>",
|
||||
"Symbol": "27.02.2024, Jan kowalski",
|
||||
"Nieaktywny": false
|
||||
},
|
||||
{
|
||||
"IkonkaNazwa": null,
|
||||
"Num": null,
|
||||
"Zawartosc": [],
|
||||
"Rozszerzenie": false,
|
||||
"Nazwa": "Platformy",
|
||||
"Url": null,
|
||||
"Dane": "<p>Platformy do wykorzystania dla uczniów w zakresie kompetencji cyfrowych:</p>",
|
||||
"Symbol": "05.12.2023, Malwina Czerwieńska",
|
||||
"Nieaktywny": false
|
||||
}
|
||||
],
|
||||
"Rozszerzenie": false,
|
||||
"Nazwa": "",
|
||||
"Url": null,
|
||||
"Dane": null,
|
||||
"Symbol": null,
|
||||
"Nieaktywny": false
|
||||
}
|
||||
],
|
||||
"success": true,
|
||||
"errorMessage": null,
|
||||
"feedback": null
|
||||
}
|
|
@ -35,6 +35,7 @@ public final class io/github/wulkanowy/sdk/Sdk {
|
|||
public final fun getKidsLuckyNumbers (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getKidsTimetable (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getKindergartenDiaryId ()I
|
||||
public final fun getLastAnnouncements (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getLastExams (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getLastGrades (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public final fun getLastHomework (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
|
@ -589,6 +590,21 @@ public final class io/github/wulkanowy/sdk/pojo/HomeworkAttachment {
|
|||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class io/github/wulkanowy/sdk/pojo/LastAnnouncement {
|
||||
public fun <init> (Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;)V
|
||||
public final fun component1 ()Ljava/time/LocalDate;
|
||||
public final fun component2 ()Ljava/lang/String;
|
||||
public final fun component3 ()Ljava/lang/String;
|
||||
public final fun copy (Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;)Lio/github/wulkanowy/sdk/pojo/LastAnnouncement;
|
||||
public static synthetic fun copy$default (Lio/github/wulkanowy/sdk/pojo/LastAnnouncement;Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/github/wulkanowy/sdk/pojo/LastAnnouncement;
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public final fun getAuthor ()Ljava/lang/String;
|
||||
public final fun getContent ()Ljava/lang/String;
|
||||
public final fun getDate ()Ljava/time/LocalDate;
|
||||
public fun hashCode ()I
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class io/github/wulkanowy/sdk/pojo/Lesson {
|
||||
public fun <init> (ILjava/time/ZonedDateTime;Ljava/time/ZonedDateTime;Ljava/time/LocalDate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZ)V
|
||||
public final fun component1 ()I
|
||||
|
|
|
@ -14,6 +14,7 @@ import io.github.wulkanowy.sdk.mapper.mapGrades
|
|||
import io.github.wulkanowy.sdk.mapper.mapGradesSemesterStatistics
|
||||
import io.github.wulkanowy.sdk.mapper.mapHebeUser
|
||||
import io.github.wulkanowy.sdk.mapper.mapHomework
|
||||
import io.github.wulkanowy.sdk.mapper.mapLastAnnouncements
|
||||
import io.github.wulkanowy.sdk.mapper.mapLuckyNumbers
|
||||
import io.github.wulkanowy.sdk.mapper.mapMailboxes
|
||||
import io.github.wulkanowy.sdk.mapper.mapMenu
|
||||
|
@ -47,6 +48,7 @@ import io.github.wulkanowy.sdk.pojo.GradeStatisticsSemester
|
|||
import io.github.wulkanowy.sdk.pojo.GradeStatisticsSubject
|
||||
import io.github.wulkanowy.sdk.pojo.Grades
|
||||
import io.github.wulkanowy.sdk.pojo.Homework
|
||||
import io.github.wulkanowy.sdk.pojo.LastAnnouncement
|
||||
import io.github.wulkanowy.sdk.pojo.LuckyNumber
|
||||
import io.github.wulkanowy.sdk.pojo.Mailbox
|
||||
import io.github.wulkanowy.sdk.pojo.Menu
|
||||
|
@ -649,6 +651,13 @@ class Sdk {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun getLastAnnouncements(): List<LastAnnouncement> = withContext(Dispatchers.IO) {
|
||||
when (mode) {
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getLastAnnouncements().mapLastAnnouncements()
|
||||
Mode.HEBE -> throw NotImplementedError("Not available in HEBE mode")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getSelfGovernments(): List<GovernmentUnit> = withContext(Dispatchers.IO) {
|
||||
when (mode) {
|
||||
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getSelfGovernments().mapToUnits()
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package io.github.wulkanowy.sdk.mapper
|
||||
|
||||
import io.github.wulkanowy.sdk.pojo.DirectorInformation
|
||||
import io.github.wulkanowy.sdk.pojo.LastAnnouncement
|
||||
import io.github.wulkanowy.sdk.scrapper.home.DirectorInformation as ScrapperDirectorInformation
|
||||
import io.github.wulkanowy.sdk.scrapper.home.LastAnnouncement as ScrapperLastAnnouncement
|
||||
|
||||
internal fun List<ScrapperDirectorInformation>.mapDirectorInformation() = map {
|
||||
DirectorInformation(
|
||||
|
@ -10,3 +12,11 @@ internal fun List<ScrapperDirectorInformation>.mapDirectorInformation() = map {
|
|||
content = it.content,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun List<ScrapperLastAnnouncement>.mapLastAnnouncements() = map {
|
||||
LastAnnouncement(
|
||||
date = it.date,
|
||||
author = it.author,
|
||||
content = it.content,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package io.github.wulkanowy.sdk.pojo
|
||||
|
||||
import java.time.LocalDate
|
||||
|
||||
data class LastAnnouncement(
|
||||
val date: LocalDate,
|
||||
val author: String,
|
||||
val content: String,
|
||||
)
|
Loading…
Reference in a new issue