forked from github/wulkanowy-mirror
Add exams API (#30)
This commit is contained in:
parent
2fbd2da60c
commit
428b372827
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import io.github.wulkanowy.api.attendance.AttendanceStatistics;
|
||||
import io.github.wulkanowy.api.attendance.AttendanceTable;
|
||||
import io.github.wulkanowy.api.exams.ExamsWeek;
|
||||
import io.github.wulkanowy.api.grades.GradesList;
|
||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
||||
@ -81,6 +82,10 @@ public class Vulcan extends Api {
|
||||
return new AttendanceTable(getStudentAndParent());
|
||||
}
|
||||
|
||||
public ExamsWeek getExamsList() throws IOException, NotLoggedInErrorException {
|
||||
return new ExamsWeek(getStudentAndParent());
|
||||
}
|
||||
|
||||
public GradesList getGradesList() throws IOException, NotLoggedInErrorException {
|
||||
return new GradesList(getStudentAndParent());
|
||||
}
|
||||
|
29
app/src/main/java/io/github/wulkanowy/api/exams/Day.java
Normal file
29
app/src/main/java/io/github/wulkanowy/api/exams/Day.java
Normal file
@ -0,0 +1,29 @@
|
||||
package io.github.wulkanowy.api.exams;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Day {
|
||||
|
||||
private List<Exam> examList = new ArrayList<>();
|
||||
|
||||
private String date = "";
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public Day setDate(String date) {
|
||||
this.date = date;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Exam> getExamList() {
|
||||
return examList;
|
||||
}
|
||||
|
||||
public Day addExam(Exam exam) {
|
||||
this.examList.add(exam);
|
||||
return this;
|
||||
}
|
||||
}
|
59
app/src/main/java/io/github/wulkanowy/api/exams/Exam.java
Normal file
59
app/src/main/java/io/github/wulkanowy/api/exams/Exam.java
Normal file
@ -0,0 +1,59 @@
|
||||
package io.github.wulkanowy.api.exams;
|
||||
|
||||
public class Exam {
|
||||
|
||||
private String subjectAndGroup = "";
|
||||
|
||||
private String type = "";
|
||||
|
||||
private String description = "";
|
||||
|
||||
private String teacher = "";
|
||||
|
||||
private String entryDate = "";
|
||||
|
||||
public String getSubjectAndGroup() {
|
||||
return subjectAndGroup;
|
||||
}
|
||||
|
||||
public Exam setSubjectAndGroup(String subjectAndGroup) {
|
||||
this.subjectAndGroup = subjectAndGroup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Exam setType(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Exam setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
|
||||
public Exam setTeacher(String teacher) {
|
||||
this.teacher = teacher;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEntryDate() {
|
||||
return entryDate;
|
||||
}
|
||||
|
||||
public Exam setEntryDate(String entryDate) {
|
||||
this.entryDate = entryDate;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package io.github.wulkanowy.api.exams;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
|
||||
public class ExamsWeek {
|
||||
|
||||
private final StudentAndParent snp;
|
||||
|
||||
private final String examsPageUrl = "Sprawdziany.mvc/Terminarz?rodzajWidoku=2&data=";
|
||||
|
||||
public ExamsWeek(StudentAndParent snp) {
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
public Week getCurrent() throws IOException {
|
||||
return getWeek("", true);
|
||||
}
|
||||
|
||||
public Week getWeek(String tick, final boolean onlyNotEmpty) throws IOException {
|
||||
Document examsPage = snp.getSnPPageDocument(examsPageUrl + tick);
|
||||
Elements examsDays = examsPage.select(".mainContainer > div:not(.navigation)");
|
||||
|
||||
List<Day> days = new ArrayList<>();
|
||||
|
||||
for (Element item : examsDays) {
|
||||
Day day = new Day();
|
||||
Element dayHeading = item.select("h2").first();
|
||||
|
||||
if (null == dayHeading && onlyNotEmpty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null != dayHeading) {
|
||||
day = new Day().setDate(dayHeading.text().split(", ")[1]);
|
||||
}
|
||||
|
||||
Elements exams = item.select("article");
|
||||
for (Element e : exams) {
|
||||
day.addExam(new Exam()
|
||||
.setSubjectAndGroup(snp.getRowDataChildValue(e, 1))
|
||||
.setType(snp.getRowDataChildValue(e, 2))
|
||||
.setDescription(snp.getRowDataChildValue(e, 3))
|
||||
.setTeacher(snp.getRowDataChildValue(e, 4).split(", ")[0])
|
||||
.setEntryDate(snp.getRowDataChildValue(e, 4).split(", ")[1])
|
||||
);
|
||||
}
|
||||
|
||||
days.add(day);
|
||||
}
|
||||
|
||||
Week week = new Week();
|
||||
week.setStartDate(examsDays.select("h2").first().text().split(" ")[1]);
|
||||
week.setDayList(days);
|
||||
|
||||
return week;
|
||||
}
|
||||
}
|
28
app/src/main/java/io/github/wulkanowy/api/exams/Week.java
Normal file
28
app/src/main/java/io/github/wulkanowy/api/exams/Week.java
Normal file
@ -0,0 +1,28 @@
|
||||
package io.github.wulkanowy.api.exams;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Week {
|
||||
|
||||
private List<Day> dayList = new ArrayList<>();
|
||||
|
||||
private String startDate = "";
|
||||
|
||||
public List<Day> getDayList() {
|
||||
return dayList;
|
||||
}
|
||||
|
||||
public Week setDayList(List<Day> dayList) {
|
||||
this.dayList = dayList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(String startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package io.github.wulkanowy.api.exams;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParentTestCase;
|
||||
|
||||
public class ExamsWeekTest extends StudentAndParentTestCase {
|
||||
|
||||
private ExamsWeek onePerDay;
|
||||
|
||||
@Before
|
||||
public void getCurrent() throws Exception {
|
||||
onePerDay = new ExamsWeek(getSnp("Sprawdziany-one-per-day.html"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWeekTest() throws Exception {
|
||||
Assert.assertEquals("23.10.2017", onePerDay.getCurrent().getStartDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDaysListTest() throws Exception {
|
||||
Assert.assertEquals(3, onePerDay.getCurrent().getDayList().size());
|
||||
Assert.assertEquals(7, onePerDay.getWeek("", false).getDayList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExamsListTest() throws Exception {
|
||||
List<Day> notEmpty = onePerDay.getCurrent().getDayList();
|
||||
Assert.assertEquals(1, notEmpty.get(0).getExamList().size());
|
||||
Assert.assertEquals(1, notEmpty.get(1).getExamList().size());
|
||||
Assert.assertEquals(1, notEmpty.get(2).getExamList().size());
|
||||
|
||||
List<Day> emptyToo = onePerDay.getWeek("", false).getDayList();
|
||||
Assert.assertEquals(1, emptyToo.get(0).getExamList().size());
|
||||
Assert.assertEquals(1, emptyToo.get(1).getExamList().size());
|
||||
Assert.assertEquals(1, emptyToo.get(4).getExamList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDayDateTest() throws Exception {
|
||||
List<Day> dayList = onePerDay.getCurrent().getDayList();
|
||||
|
||||
Assert.assertEquals("23.10.2017", dayList.get(0).getDate());
|
||||
Assert.assertEquals("24.10.2017", dayList.get(1).getDate());
|
||||
Assert.assertEquals("27.10.2017", dayList.get(2).getDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExamSubjectAndGroupTest() throws Exception {
|
||||
List<Day> dayList = onePerDay.getCurrent().getDayList();
|
||||
|
||||
Assert.assertEquals("Sieci komputerowe 3Ti|zaw2", dayList.get(0).getExamList().get(0).getSubjectAndGroup());
|
||||
Assert.assertEquals("Język angielski 3Ti|J1", dayList.get(1).getExamList().get(0).getSubjectAndGroup());
|
||||
Assert.assertEquals("Metodologia programowania 3Ti|zaw2", dayList.get(2).getExamList().get(0).getSubjectAndGroup());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExamTypeTest() throws Exception {
|
||||
List<Day> dayList = onePerDay.getCurrent().getDayList();
|
||||
|
||||
Assert.assertEquals("Sprawdzian", dayList.get(0).getExamList().get(0).getType());
|
||||
Assert.assertEquals("Sprawdzian", dayList.get(1).getExamList().get(0).getType());
|
||||
Assert.assertEquals("Sprawdzian", dayList.get(2).getExamList().get(0).getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExamDescriptionTest() throws Exception {
|
||||
List<Day> dayList = onePerDay.getCurrent().getDayList();
|
||||
|
||||
Assert.assertEquals("Łącza danych", dayList.get(0).getExamList().get(0).getDescription());
|
||||
Assert.assertEquals("Czasy teraźniejsze", dayList.get(1).getExamList().get(0).getDescription());
|
||||
Assert.assertEquals("", dayList.get(2).getExamList().get(0).getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExamTeacherTest() throws Exception {
|
||||
List<Day> dayList = onePerDay.getCurrent().getDayList();
|
||||
|
||||
Assert.assertEquals("Adam Wiśniewski [AW]", dayList.get(0).getExamList().get(0).getTeacher());
|
||||
Assert.assertEquals("Natalia Nowak [NN]", dayList.get(1).getExamList().get(0).getTeacher());
|
||||
Assert.assertEquals("Małgorzata Nowacka [MN]", dayList.get(2).getExamList().get(0).getTeacher());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExamEntryDateTest() throws Exception {
|
||||
List<Day> dayList = onePerDay.getCurrent().getDayList();
|
||||
|
||||
Assert.assertEquals("16.10.2017", dayList.get(0).getExamList().get(0).getEntryDate());
|
||||
Assert.assertEquals("17.10.2017", dayList.get(1).getExamList().get(0).getEntryDate());
|
||||
Assert.assertEquals("16.10.2017", dayList.get(2).getExamList().get(0).getEntryDate());
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Terminarz sprawdzianów</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<h1>Sprawdziany</h1>
|
||||
<h2>Tydzień 23.10.2017 - 29.10.2017</h2>
|
||||
<div>
|
||||
<h2>poniedziałek, 23.10.2017</h2>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Przedmiot i grupa:</div>
|
||||
<div class="wartosc">Sieci komputerowe 3Ti|zaw2</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Rodzaj sprawdzianu:</div>
|
||||
<div class="wartosc">Sprawdzian</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Opis:</div>
|
||||
<div class="wartosc">Łącza danych</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel i data wpisu:</div>
|
||||
<div class="wartosc">Adam Wiśniewski [AW], 16.10.2017</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div>
|
||||
<h2>wtorek, 24.10.2017</h2>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Przedmiot i grupa:</div>
|
||||
<div class="wartosc">Język angielski 3Ti|J1</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Rodzaj sprawdzianu:</div>
|
||||
<div class="wartosc">Sprawdzian</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Opis:</div>
|
||||
<div class="wartosc">Czasy teraźniejsze</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel i data wpisu:</div>
|
||||
<div class="wartosc">Natalia Nowak [NN], 17.10.2017</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div>
|
||||
<h2>piątek, 27.10.2017</h2>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Przedmiot i grupa:</div>
|
||||
<div class="wartosc">Metodologia programowania 3Ti|zaw2</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Rodzaj sprawdzianu:</div>
|
||||
<div class="wartosc">Sprawdzian</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Opis:</div>
|
||||
<div class="wartosc"></div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel i data wpisu:</div>
|
||||
<div class="wartosc">Małgorzata Nowacka [MN], 16.10.2017</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div class="navigation">
|
||||
<a href="/symbol/123456/Sprawdziany.mvc/Terminarz?data=636437088000000000&rokSzkolny=2017&rodzajWidoku=2" class="button-prev">Poprzedni tydzień</a>
|
||||
<a href="/symbol/123456/Sprawdziany.mvc/Terminarz?data=636449184000000000&rokSzkolny=2017&rodzajWidoku=2" class="button-next">Następny tydzień</a>
|
||||
</div>
|
||||
</main>
|
||||
<footer>wersja: 17.08.0001.24874</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user