Add exams API (#30)
This commit is contained in:

committed by
Rafał Borcz

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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user