forked from github/wulkanowy-mirror
Add homework api (#150)
This commit is contained in:
parent
d7eac45e96
commit
0f5a801464
@ -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<Homework> getHomework(String date) throws VulcanException, IOException {
|
||||
return new HomeworkList(getStudentAndParent()).getHomework(date);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SubjectsList getSubjectsList() throws IOException, VulcanException {
|
||||
return new SubjectsList(getStudentAndParent());
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
)
|
@ -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<Homework> {
|
||||
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())
|
||||
)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Zadania domowe</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<h1>Zadania domowe</h1>
|
||||
|
||||
<h2>poniedziałek, 23.10.2017</h2>
|
||||
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Przedmiot:</div>
|
||||
<div class="wartosc">Sieci komputerowe i administrowanie sieciami</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Opis:</div>
|
||||
<div class="wartosc">Zadania egzaminacyjne
|
||||
</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel i data wpisu:</div>
|
||||
<div class="wartosc">Słowacki Juliusz [SJ], 16.10.2017</div>
|
||||
</div>
|
||||
</article>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Przedmiot:</div>
|
||||
<div class="wartosc">Naprawa komputera</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Opis:</div>
|
||||
<div class="wartosc">Test diagnozujący</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel i data wpisu:</div>
|
||||
<div class="wartosc">Mickiewicz Adam [MA], 25.10.2017</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
</main>
|
||||
<footer>wersja: 18.02.0007.28151</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user