Add ability to change grades list semester (#10)
This commit is contained in:
35
app/src/main/java/io/github/wulkanowy/api/Semester.java
Normal file
35
app/src/main/java/io/github/wulkanowy/api/Semester.java
Normal file
@ -0,0 +1,35 @@
|
||||
package io.github.wulkanowy.api;
|
||||
|
||||
public class Semester {
|
||||
|
||||
private String number = "";
|
||||
private String id = "";
|
||||
private boolean isCurrent = false;
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public Semester setNumber(String number) {
|
||||
this.number = number;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Semester setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
return isCurrent;
|
||||
}
|
||||
|
||||
public Semester setCurrent(boolean current) {
|
||||
isCurrent = current;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -4,8 +4,11 @@ import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
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 java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -15,15 +18,22 @@ public class StudentAndParent extends Vulcan {
|
||||
|
||||
private String startPageUrl = "https://uonetplus.vulcan.net.pl/{locationID}/Start.mvc/Index";
|
||||
|
||||
private String locationID;
|
||||
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/"
|
||||
+ "Oceny/Wszystkie";
|
||||
|
||||
private String uonetPlusOpiekunUrl;
|
||||
private String locationID = "";
|
||||
|
||||
private String uonetPlusOpiekunUrl = "";
|
||||
|
||||
public StudentAndParent(Cookies cookies, String locID) throws IOException {
|
||||
this.cookies = cookies;
|
||||
this.locationID = locID;
|
||||
}
|
||||
|
||||
public String getGradesPageUrl() {
|
||||
return gradesPageUrl;
|
||||
}
|
||||
|
||||
public StudentAndParent setUp() throws IOException {
|
||||
startPageUrl = startPageUrl.replace("{locationID}", locationID);
|
||||
|
||||
@ -67,4 +77,42 @@ public class StudentAndParent extends Vulcan {
|
||||
public String getRowDataChildValue(Element e, int index) {
|
||||
return e.select(".daneWiersz .wartosc").get(index - 1).text();
|
||||
}
|
||||
|
||||
public List<Semester> getSemesters() throws IOException, LoginErrorException {
|
||||
String url = getGradesPageUrl();
|
||||
url = url.replace("{locationID}", getLocationID());
|
||||
url = url.replace("{ID}", getID());
|
||||
|
||||
Document gradesPage = getPageByUrl(url);
|
||||
Elements semesterOptions = gradesPage.select("#okresyKlasyfikacyjneDropDownList option");
|
||||
|
||||
List<Semester> semesters = new ArrayList<>();
|
||||
|
||||
for (Element e : semesterOptions) {
|
||||
Semester semester = new Semester()
|
||||
.setId(e.text())
|
||||
.setNumber(e.attr("value"));
|
||||
|
||||
if ("selected".equals(e.attr("selected"))) {
|
||||
semester.setCurrent(true);
|
||||
}
|
||||
|
||||
semesters.add(semester);
|
||||
}
|
||||
|
||||
return semesters;
|
||||
}
|
||||
|
||||
public Semester getCurrentSemester(List<Semester> semesterList)
|
||||
throws IOException, LoginErrorException {
|
||||
Semester current = null;
|
||||
for (Semester s : semesterList) {
|
||||
if (s.isCurrent()) {
|
||||
current = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package io.github.wulkanowy.api;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Vulcan {
|
||||
@ -23,4 +27,11 @@ public abstract class Vulcan {
|
||||
this.cookies.addItems(cookies);
|
||||
return this.cookies;
|
||||
}
|
||||
|
||||
public Document getPageByUrl(String url) throws IOException {
|
||||
return Jsoup.connect(url)
|
||||
.followRedirects(true)
|
||||
.cookies(getCookies())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.api.grades;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
@ -20,8 +19,8 @@ public class GradesList extends Vulcan {
|
||||
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
private String gradesPageUrl =
|
||||
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Oceny/Wszystkie?details=2";
|
||||
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}"
|
||||
+ "/Oceny/Wszystkie?details=2&okres=";
|
||||
|
||||
private List<Grade> grades = new ArrayList<>();
|
||||
|
||||
@ -30,14 +29,20 @@ public class GradesList extends Vulcan {
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
public String getGradesPageUrl() {
|
||||
return gradesPageUrl;
|
||||
}
|
||||
|
||||
public List<Grade> getAll() throws IOException, LoginErrorException {
|
||||
gradesPageUrl = gradesPageUrl.replace("{locationID}", snp.getLocationID());
|
||||
gradesPageUrl = gradesPageUrl.replace("{ID}", snp.getID());
|
||||
return getAll(snp.getCurrentSemester(snp.getSemesters()).getNumber());
|
||||
}
|
||||
|
||||
Document marksPage = Jsoup.connect(gradesPageUrl)
|
||||
.cookies(getCookies())
|
||||
.get();
|
||||
public List<Grade> getAll(String semester) throws IOException, LoginErrorException {
|
||||
String url = getGradesPageUrl();
|
||||
url = url.replace("{locationID}", snp.getLocationID());
|
||||
url = url.replace("{ID}", snp.getID());
|
||||
|
||||
Document marksPage = getPageByUrl(url + semester);
|
||||
Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||
|
||||
for (Element row : marksRows) {
|
||||
|
@ -14,8 +14,8 @@ public class Notes extends Vulcan {
|
||||
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
private String notesPageUrl =
|
||||
"https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/UwagiOsiagniecia.mvc/Wszystkie";
|
||||
private String notesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/"
|
||||
+ "UwagiOsiagniecia.mvc/Wszystkie";
|
||||
|
||||
public Notes(Cookies cookies, StudentAndParent snp) {
|
||||
this.cookies = cookies;
|
||||
|
Reference in New Issue
Block a user