Add to Grade semester and symbol properties (#12)
This commit is contained in:
@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.grades.Grades;
|
||||
import io.github.wulkanowy.api.grades.GradesList;
|
||||
import io.github.wulkanowy.api.grades.Subject;
|
||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||
@ -105,7 +106,8 @@ public class MarksFragment extends Fragment {
|
||||
subjectsName.add(subject.getName());
|
||||
}
|
||||
|
||||
GradesList gradesList = new GradesList(snp.getCookiesObject(), snp);
|
||||
Grades gradesObject = new Grades(snp.getCookiesObject(), snp);
|
||||
GradesList gradesList = new GradesList(gradesObject, snp);
|
||||
GradesDatabase gradesDatabase = new GradesDatabase(mContext);
|
||||
gradesDatabase.open();
|
||||
gradesDatabase.put(gradesList.getAll());
|
||||
|
@ -84,6 +84,11 @@ public class StudentAndParent extends Vulcan {
|
||||
url = url.replace("{ID}", getID());
|
||||
|
||||
Document gradesPage = getPageByUrl(url);
|
||||
|
||||
return getSemesters(gradesPage);
|
||||
}
|
||||
|
||||
public List<Semester> getSemesters(Document gradesPage) {
|
||||
Elements semesterOptions = gradesPage.select("#okresyKlasyfikacyjneDropDownList option");
|
||||
|
||||
List<Semester> semesters = new ArrayList<>();
|
||||
|
@ -10,23 +10,23 @@ public class Grade {
|
||||
|
||||
private int subjectID;
|
||||
|
||||
private String subject;
|
||||
private String subject = "";
|
||||
|
||||
private String value;
|
||||
private String value = "";
|
||||
|
||||
private String color;
|
||||
private String color = "";
|
||||
|
||||
private String symbol;
|
||||
private String symbol = "";
|
||||
|
||||
private String description;
|
||||
private String description = "";
|
||||
|
||||
private String weight;
|
||||
private String weight = "";
|
||||
|
||||
private String date;
|
||||
private String date = "";
|
||||
|
||||
private String teacher;
|
||||
private String teacher = "";
|
||||
|
||||
private String semester;
|
||||
private String semester = "";
|
||||
|
||||
private boolean isNew;
|
||||
|
||||
@ -156,6 +156,7 @@ public class Grade {
|
||||
|
||||
public Grade setIsNew(boolean isNew) {
|
||||
this.isNew = isNew;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
28
app/src/main/java/io/github/wulkanowy/api/grades/Grades.java
Normal file
28
app/src/main/java/io/github/wulkanowy/api/grades/Grades.java
Normal file
@ -0,0 +1,28 @@
|
||||
package io.github.wulkanowy.api.grades;
|
||||
|
||||
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 Grades extends Vulcan {
|
||||
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
public Grades(Cookies cookies, StudentAndParent snp) {
|
||||
this.cookies = cookies;
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
//TODO: move to snp
|
||||
public Document getGradesPageDocument(String url) throws IOException, LoginErrorException {
|
||||
return getPageByUrl(url
|
||||
.replace("{locationID}", snp.getLocationID())
|
||||
.replace("{ID}", snp.getID())
|
||||
);
|
||||
}
|
||||
}
|
@ -10,22 +10,23 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.Semester;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class GradesList extends Vulcan {
|
||||
|
||||
private Grades grades = null;
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}"
|
||||
+ "/Oceny/Wszystkie?details=2&okres=";
|
||||
|
||||
private List<Grade> grades = new ArrayList<>();
|
||||
private List<Grade> gradesList = new ArrayList<>();
|
||||
|
||||
public GradesList(Cookies cookies, StudentAndParent snp) {
|
||||
this.cookies = cookies;
|
||||
public GradesList(Grades grades, StudentAndParent snp) {
|
||||
this.grades = grades;
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
@ -34,39 +35,41 @@ public class GradesList extends Vulcan {
|
||||
}
|
||||
|
||||
public List<Grade> getAll() throws IOException, LoginErrorException {
|
||||
return getAll(snp.getCurrentSemester(snp.getSemesters()).getNumber());
|
||||
return getAll("");
|
||||
}
|
||||
|
||||
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 gradesPage = grades.getGradesPageDocument(getGradesPageUrl() + semester);
|
||||
Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||
Semester currentSemester = snp.getCurrentSemester(snp.getSemesters(gradesPage));
|
||||
|
||||
Document marksPage = getPageByUrl(url + semester);
|
||||
Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||
|
||||
for (Element row : marksRows) {
|
||||
Pattern pattern = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");
|
||||
Matcher matcher = pattern.matcher(
|
||||
row.select("td:nth-child(2) span.ocenaCzastkowa").attr("style"));
|
||||
String color;
|
||||
if (!matcher.find()) {
|
||||
color = "000000";
|
||||
} else {
|
||||
color = matcher.group(1);
|
||||
for (Element row : gradesRows) {
|
||||
if ("Brak ocen".equals(row.select("td:nth-child(2)").text())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
grades.add(new Grade()
|
||||
String descriptions = row.select("td:nth-child(3)").text();
|
||||
String symbol = descriptions.split(", ")[0];
|
||||
String description = descriptions.replaceFirst(symbol, "").replaceFirst(", ", "");
|
||||
|
||||
Pattern pattern = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");
|
||||
Matcher matcher = pattern.matcher(row.select("td:nth-child(2) span.ocenaCzastkowa")
|
||||
.attr("style"));
|
||||
String color = matcher.find() ? matcher.group(1) : "";
|
||||
|
||||
gradesList.add(new Grade()
|
||||
.setSubject(row.select("td:nth-child(1)").text())
|
||||
.setValue(row.select("td:nth-child(2)").text())
|
||||
.setColor(color)
|
||||
.setDescription(row.select("td:nth-child(3)").text())
|
||||
.setSymbol(symbol)
|
||||
.setDescription(description)
|
||||
.setWeight(row.select("td:nth-child(4)").text())
|
||||
.setDate(row.select("td:nth-child(5)").text())
|
||||
.setTeacher(row.select("td:nth-child(6)").text())
|
||||
.setSemester(currentSemester.getNumber())
|
||||
);
|
||||
}
|
||||
|
||||
return grades;
|
||||
return gradesList;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -32,9 +31,7 @@ public class SubjectsList extends Vulcan {
|
||||
subjectsPageUrl = subjectsPageUrl.replace("{locationID}", snp.getLocationID());
|
||||
subjectsPageUrl = subjectsPageUrl.replace("{ID}", snp.getID());
|
||||
|
||||
Document subjectPage = Jsoup.connect(subjectsPageUrl)
|
||||
.cookies(getCookies())
|
||||
.get();
|
||||
Document subjectPage = getPageByUrl(subjectsPageUrl);
|
||||
|
||||
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");
|
||||
|
||||
|
Reference in New Issue
Block a user