forked from github/wulkanowy-mirror
Add school api (#11)
This commit is contained in:
parent
0aa083c8aa
commit
4539a62de9
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SchoolInfoTest extends SchoolTest {
|
||||
|
||||
private SchoolInfo schoolInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
schoolInfo = new SchoolInfo(school, snp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchoolDataTest() throws Exception {
|
||||
SchoolData schoolData = schoolInfo.getSchoolData();
|
||||
|
||||
Assert.assertEquals("Zespół Szkół nr 64", schoolData.getName());
|
||||
Assert.assertEquals("ul. Wiśniowa 128, 01-234 Rogalowo, Nibylandia",
|
||||
schoolData.getAddress());
|
||||
Assert.assertEquals("55 5555555", schoolData.getPhoneNumber());
|
||||
Assert.assertEquals("Antoni Sobczyk", schoolData.getHeadmaster());
|
||||
Assert.assertArrayEquals(new String[]{
|
||||
"Zofia Czerwińska [ZC]",
|
||||
"Aleksander Krzemiński [AK]",
|
||||
"Karolina Kowalska [KK]",
|
||||
"Bartek Dąbrowski [BD]"
|
||||
}, schoolData.getPedagogues());
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import io.github.wulkanowy.api.FixtureHelper;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
|
||||
public class SchoolTest {
|
||||
|
||||
protected School school;
|
||||
protected StudentAndParent snp;
|
||||
private String fixtureFileName = "Szkola.html";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
|
||||
|
||||
Document schoolPageDocument = Jsoup.parse(input);
|
||||
|
||||
school = Mockito.mock(School.class);
|
||||
Mockito.when(school.getSchoolPageDocument()).thenReturn(schoolPageDocument);
|
||||
snp = Mockito.mock(StudentAndParent.class);
|
||||
Mockito.when(snp.getRowDataChildValue(Mockito.any(Element.class),
|
||||
Mockito.anyInt())).thenCallRealMethod();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package io.github.wulkanowy.api.school;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TeachersInfoTest extends SchoolTest {
|
||||
|
||||
private TeachersInfo teachersInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
teachersInfo = new TeachersInfo(school);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTeachersDataTest() throws Exception {
|
||||
TeachersData teachersData = teachersInfo.getTeachersData();
|
||||
|
||||
Assert.assertEquals("1a", teachersData.getClassName());
|
||||
Assert.assertArrayEquals(new String[]{
|
||||
"Karolina Kowalska [AN]",
|
||||
"Antoni Sobczyk [AS]"
|
||||
}, teachersData.getClassTeacher());
|
||||
|
||||
List<Subject> subjects = teachersData.getSubjects();
|
||||
|
||||
Assert.assertEquals("Biologia", subjects.get(0).getName());
|
||||
Assert.assertArrayEquals(new String[]{"Karolina Kowalska [AN]"},
|
||||
subjects.get(0).getTeachers());
|
||||
Assert.assertEquals("Karolina Kowalska [AN]",
|
||||
subjects.get(0).getTeachers()[0]);
|
||||
|
||||
Assert.assertEquals("Język angielski", subjects.get(6).getName());
|
||||
Assert.assertArrayEquals(new String[]{
|
||||
"Karolina Kowalska [AN]",
|
||||
"Mateusz Kowal [MK]",
|
||||
"Amelia Mazur [AM]"
|
||||
}, subjects.get(6).getTeachers());
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Szkoła i nauczyciele</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<h1>Szkoła</h1>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<span class="tytul">Nazwa szkoły:</span>
|
||||
<span class="wartosc">Zespół Szkół nr 64</span>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<span class="tytul">Adres szkoły:</span>
|
||||
<span class="wartosc">ul. Wiśniowa 128, 01-234 Rogalowo, Nibylandia</span>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<span class="tytul">Telefon:</span>
|
||||
<span class="wartosc">55 5555555</span>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<span class="tytul">Imię i nazwisko dyrektora:</span>
|
||||
<span class="wartosc">Antoni Sobczyk</span>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<span class="tytul">Imię i nazwisko pedagoga:</span>
|
||||
<span class="wartosc">Zofia Czerwińska [ZC], Aleksander Krzemiński [AK], Karolina Kowalska [KK], Bartek Dąbrowski [BD]</span>
|
||||
</div>
|
||||
</article>
|
||||
<h1>Nauczyciele</h1>
|
||||
<p>
|
||||
Klasa: 1a, Wychowawcy:
|
||||
Karolina Kowalska [AN], Antoni Sobczyk [AS]</p>
|
||||
<br/>
|
||||
<table>
|
||||
<thead>
|
||||
<tr class="title">
|
||||
<th>Lp.</th>
|
||||
<th>Przedmiot</th>
|
||||
<th>Nauczyciel</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>Biologia</td>
|
||||
<td>Karolina Kowalska [AN]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>Chemia</td>
|
||||
<td>Zofia Czerwińska [NA]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>Edukacja dla bezpieczeństwa</td>
|
||||
<td>Aleksandra Krajewska [AK]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>Fizyka</td>
|
||||
<td>Stanisław Krupa [BS]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td>Geografia</td>
|
||||
<td>Aleksandra Wójtowicz [AW]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
<td>Historia</td>
|
||||
<td>Sara Wierzbicka [KB]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7</td>
|
||||
<td>Język angielski</td>
|
||||
<td>Karolina Kowalska [AN], Mateusz Kowal [MK], Amelia Mazur [AM]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td>Język niemiecki</td>
|
||||
<td>Mateusz Kowal [MK], Barbara Markowska [BM]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>9</td>
|
||||
<td>Język polski</td>
|
||||
<td>Michał Mazur [MM]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>10</td>
|
||||
<td>Matematyka</td>
|
||||
<td>Szymon Wojciechowski [SW]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>11</td>
|
||||
<td>Plastyka</td>
|
||||
<td>Michał Mazur [MM]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>12</td>
|
||||
<td>Religia</td>
|
||||
<td>Maja Wiśniewska [M]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>13</td>
|
||||
<td>Wiedza o społeczeństwie</td>
|
||||
<td>Karolina Kowalska [AN]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>14</td>
|
||||
<td>Wychowanie do życia w rodzinie</td>
|
||||
<td>Zofia Czerwińska [NA]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>15</td>
|
||||
<td>Wychowanie fizyczne</td>
|
||||
<td>Karolina Kowalska [AN], Liliana Kowal [LK]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>16</td>
|
||||
<td>Zajęcia techniczne</td>
|
||||
<td>Bartek Dąbrowski [BD]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>17</td>
|
||||
<td>Zajęcia z wychowawcą</td>
|
||||
<td>Karolina Kowalska [AN]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
<footer>wersja: 17.02.0000.23328</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user