Add school api (#11)
This commit is contained in:
32
app/src/main/java/io/github/wulkanowy/api/school/School.java
Normal file
32
app/src/main/java/io/github/wulkanowy/api/school/School.java
Normal file
@ -0,0 +1,32 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class School extends Vulcan {
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
private String schoolPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/"
|
||||
+ "Szkola.mvc/Nauczyciele";
|
||||
|
||||
public School(Cookies cookies, StudentAndParent snp) {
|
||||
this.cookies = cookies;
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
public Document getSchoolPageDocument() throws IOException, LoginErrorException {
|
||||
schoolPageUrl = schoolPageUrl.replace("{locationID}", snp.getLocationID());
|
||||
schoolPageUrl = schoolPageUrl.replace("{ID}", snp.getID());
|
||||
|
||||
return Jsoup.connect(schoolPageUrl)
|
||||
.cookies(getCookies())
|
||||
.get();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
public class SchoolData {
|
||||
|
||||
private String name = "";
|
||||
private String address = "";
|
||||
private String phoneNumber = "";
|
||||
private String headmaster = "";
|
||||
private String[] pedagogue;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SchoolData setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public SchoolData setAddress(String address) {
|
||||
this.address = address;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public SchoolData setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getHeadmaster() {
|
||||
return headmaster;
|
||||
}
|
||||
|
||||
public SchoolData setHeadmaster(String headmaster) {
|
||||
this.headmaster = headmaster;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getPedagogues() {
|
||||
return pedagogue;
|
||||
}
|
||||
|
||||
public SchoolData setPedagogue(String[] pedagogue) {
|
||||
this.pedagogue = pedagogue;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class SchoolInfo extends Vulcan {
|
||||
|
||||
private School school = null;
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
public SchoolInfo(School school, StudentAndParent snp) {
|
||||
this.school = school;
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
public SchoolData getSchoolData() throws IOException, LoginErrorException {
|
||||
Element e = school.getSchoolPageDocument().select(".mainContainer > article").get(0);
|
||||
|
||||
return new SchoolData()
|
||||
.setName(snp.getRowDataChildValue(e, 1))
|
||||
.setAddress(snp.getRowDataChildValue(e, 2))
|
||||
.setPhoneNumber(snp.getRowDataChildValue(e, 3))
|
||||
.setHeadmaster(snp.getRowDataChildValue(e, 4))
|
||||
.setPedagogue(snp.getRowDataChildValue(e, 5).split(", "));
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
public class Subject {
|
||||
private String name = "";
|
||||
private String[] teachers;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Subject setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getTeachers() {
|
||||
return teachers;
|
||||
}
|
||||
|
||||
public Subject setTeachers(String[] teachers) {
|
||||
this.teachers = teachers;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TeachersData {
|
||||
private String className = "";
|
||||
private String[] classTeacher;
|
||||
private List<Subject> subjects;
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public TeachersData setClassName(String className) {
|
||||
this.className = className;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getClassTeacher() {
|
||||
return classTeacher;
|
||||
}
|
||||
|
||||
public TeachersData setClassTeacher(String[] classTeacher) {
|
||||
this.classTeacher = classTeacher;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Subject> getSubjects() {
|
||||
return subjects;
|
||||
}
|
||||
|
||||
public TeachersData setSubjects(List<Subject> subjects) {
|
||||
this.subjects = subjects;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
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.Vulcan;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class TeachersInfo extends Vulcan {
|
||||
|
||||
private School school = null;
|
||||
|
||||
public TeachersInfo(School school) {
|
||||
this.school = school;
|
||||
}
|
||||
|
||||
public TeachersData getTeachersData() throws IOException, LoginErrorException {
|
||||
Document doc = school.getSchoolPageDocument();
|
||||
Elements rows = doc.select(".mainContainer > table tbody tr");
|
||||
String description = doc.select(".mainContainer > p").first().text();
|
||||
|
||||
List<Subject> subjects = new ArrayList<>();
|
||||
|
||||
for (Element subject : rows) {
|
||||
subjects.add(new Subject()
|
||||
.setName(subject.select("td").get(1).text())
|
||||
.setTeachers(subject.select("td").get(2).text().split(", "))
|
||||
);
|
||||
}
|
||||
|
||||
return new TeachersData()
|
||||
.setClassName(description.split(", ")[0].split(": ")[1].trim())
|
||||
.setClassTeacher(description.split("Wychowawcy:")[1].trim().split(", "))
|
||||
.setSubjects(subjects);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user