diff --git a/api/src/main/java/io/github/wulkanowy/api/Vulcan.java b/api/src/main/java/io/github/wulkanowy/api/Vulcan.java index d867773a..70cf382e 100644 --- a/api/src/main/java/io/github/wulkanowy/api/Vulcan.java +++ b/api/src/main/java/io/github/wulkanowy/api/Vulcan.java @@ -20,6 +20,8 @@ import io.github.wulkanowy.api.grades.GradesList; import io.github.wulkanowy.api.grades.GradesSummary; import io.github.wulkanowy.api.grades.SubjectsList; import io.github.wulkanowy.api.grades.Summary; +import io.github.wulkanowy.api.homework.Homework; +import io.github.wulkanowy.api.homework.HomeworkList; import io.github.wulkanowy.api.messages.Messages; import io.github.wulkanowy.api.mobile.RegisterDevice; import io.github.wulkanowy.api.mobile.RegisteredDevices; @@ -116,6 +118,10 @@ public class Vulcan { return new GradesSummary(getStudentAndParent()).getSummary(semester); } + public List getHomework(String date) throws VulcanException, IOException { + return new HomeworkList(getStudentAndParent()).getHomework(date); + } + @Deprecated public SubjectsList getSubjectsList() throws IOException, VulcanException { return new SubjectsList(getStudentAndParent()); diff --git a/api/src/main/java/io/github/wulkanowy/api/exams/Exams.kt b/api/src/main/java/io/github/wulkanowy/api/exams/Exams.kt index e0126a36..f95c2554 100644 --- a/api/src/main/java/io/github/wulkanowy/api/exams/Exams.kt +++ b/api/src/main/java/io/github/wulkanowy/api/exams/Exams.kt @@ -14,7 +14,7 @@ class Exams(private val snp: SnP) { .select(".mainContainer > div:not(.navigation)").map { val date = getFormattedDate(it.selectFirst("h2")?.text()?.split(", ")?.last()?.trim()) - it.select("article").map { getExam(it, date) } + it.select("article").mapIndexed { _, element -> getExam(element, date) } }.flatten() } diff --git a/api/src/main/java/io/github/wulkanowy/api/homework/Homework.kt b/api/src/main/java/io/github/wulkanowy/api/homework/Homework.kt new file mode 100644 index 00000000..6c1cdac4 --- /dev/null +++ b/api/src/main/java/io/github/wulkanowy/api/homework/Homework.kt @@ -0,0 +1,16 @@ +package io.github.wulkanowy.api.homework + +data class Homework( + + val date: String, + + val subject: String, + + val content: String, + + val teacher: String, + + val teacherSymbol: String, + + val entryDate: String +) diff --git a/api/src/main/java/io/github/wulkanowy/api/homework/HomeworkList.kt b/api/src/main/java/io/github/wulkanowy/api/homework/HomeworkList.kt new file mode 100644 index 00000000..1a6ea398 --- /dev/null +++ b/api/src/main/java/io/github/wulkanowy/api/homework/HomeworkList.kt @@ -0,0 +1,28 @@ +package io.github.wulkanowy.api.homework + +import io.github.wulkanowy.api.SnP +import io.github.wulkanowy.api.getDateAsTick +import io.github.wulkanowy.api.getFormattedDate +import org.jsoup.nodes.Element + +class HomeworkList(private val snp: SnP) { + + fun getHomework(date: String = ""): List { + return snp.getSnPPageDocument("ZadaniaDomowe.mvc?data=${getDateAsTick(date)}&rodzajWidoku=Dzien") + .select(".mainContainer article").map { + getItem(it, date) + } + } + + private fun getItem(e: Element, date: String): Homework { + val teacherAndDate = snp.getRowDataChildValue(e, 3).split(", ") + return Homework( + date = date, + subject = snp.getRowDataChildValue(e, 1), + teacher = teacherAndDate.first().split(" [").first(), + teacherSymbol = teacherAndDate.first().split(" [").last().replace("]", ""), + content = snp.getRowDataChildValue(e, 2), + entryDate = getFormattedDate(teacherAndDate.last()) + ) + } +} diff --git a/api/src/test/java/io/github/wulkanowy/api/homework/HomeworkListTest.kt b/api/src/test/java/io/github/wulkanowy/api/homework/HomeworkListTest.kt new file mode 100644 index 00000000..5fe53a78 --- /dev/null +++ b/api/src/test/java/io/github/wulkanowy/api/homework/HomeworkListTest.kt @@ -0,0 +1,44 @@ +package io.github.wulkanowy.api.homework + +import io.github.wulkanowy.api.StudentAndParentTestCase +import org.junit.Assert.assertEquals +import org.junit.Test + +class HomeworkListTest : StudentAndParentTestCase() { + + private val snp by lazy { getSnp("ZadaniaDomowe.html") } + + @Test fun getHomework() { + assertEquals(2, HomeworkList(snp).getHomework().size) + } + + @Test fun getDate() { + assertEquals("2018-08-13", HomeworkList(snp).getHomework("2018-08-13")[0].date) + assertEquals("1970-01-01", HomeworkList(snp).getHomework("1970-01-01")[1].date) + } + + @Test fun getSubject() { + assertEquals("Sieci komputerowe i administrowanie sieciami", HomeworkList(snp).getHomework()[0].subject) + assertEquals("Naprawa komputera", HomeworkList(snp).getHomework()[1].subject) + } + + @Test fun getContent() { + assertEquals("Zadania egzaminacyjne", HomeworkList(snp).getHomework()[0].content) + assertEquals("Test diagnozujący", HomeworkList(snp).getHomework()[1].content) + } + + @Test fun getTeacher() { + assertEquals("Słowacki Juliusz", HomeworkList(snp).getHomework()[0].teacher) + assertEquals("Mickiewicz Adam", HomeworkList(snp).getHomework()[1].teacher) + } + + @Test fun getTeacherSymbol() { + assertEquals("SJ", HomeworkList(snp).getHomework()[0].teacherSymbol) + assertEquals("MA", HomeworkList(snp).getHomework()[1].teacherSymbol) + } + + @Test fun getEntryDate() { + assertEquals("2017-10-16", HomeworkList(snp).getHomework()[0].entryDate) + assertEquals("2017-10-25", HomeworkList(snp).getHomework()[1].entryDate) + } +} diff --git a/api/src/test/resources/io/github/wulkanowy/api/homework/ZadaniaDomowe.html b/api/src/test/resources/io/github/wulkanowy/api/homework/ZadaniaDomowe.html new file mode 100644 index 00000000..ec68d2ab --- /dev/null +++ b/api/src/test/resources/io/github/wulkanowy/api/homework/ZadaniaDomowe.html @@ -0,0 +1,46 @@ + + + + + Witryna ucznia i rodzica – Zadania domowe + + +
+

Zadania domowe

+ +

poniedziałek, 23.10.2017

+ +
+
+
Przedmiot:
+
Sieci komputerowe i administrowanie sieciami
+
+
+
Opis:
+
Zadania egzaminacyjne +
+
+
+
Nauczyciel i data wpisu:
+
Słowacki Juliusz [SJ], 16.10.2017
+
+
+
+
+
Przedmiot:
+
Naprawa komputera
+
+
+
Opis:
+
Test diagnozujący
+
+
+
Nauczyciel i data wpisu:
+
Mickiewicz Adam [MA], 25.10.2017
+
+
+ +
+ + +