1
0

Add exams API (#30)

This commit is contained in:
Mikołaj Pich
2017-11-17 16:50:49 +01:00
committed by Rafał Borcz
parent 2fbd2da60c
commit 428b372827
7 changed files with 368 additions and 0 deletions

View File

@ -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());
}

View 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;
}
}

View 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;
}
}

View File

@ -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;
}
}

View 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;
}
}