Skip to content

Commit

Permalink
Hotfix substitutes
Browse files Browse the repository at this point in the history
  • Loading branch information
PAException committed Oct 3, 2023
1 parent feb8760 commit 0884053
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ public void updateSubstitutes() {
int startClasses = navbar.html().indexOf(startIdentifier);
int endClasses = navbar.html().indexOf(endIdentifier);

//Extract classes and check for changes, if changed update to informationController
String rawClasses = navbar.html().substring(startClasses, endClasses);
if (this.checkChanges(rawClasses, "classes")) {
rawClasses = rawClasses
.replace(startIdentifier, "")
.replace(endIdentifier, "")
.replaceAll("\"", "");

//Update current classes
this.informationController.setCurrentClasses(rawClasses.split(","));
LOGGER.trace("[SUBSTITUTE] Updated classes");
} else LOGGER.trace("[SUBSTITUTE] Classes did not change");
// --> school might have changed the declaration of the classes
if (startClasses >= 0 && endClasses > startClasses) {
//Extract classes and check for changes, if changed update to informationController
String rawClasses = navbar.html().substring(startClasses, endClasses);
if (this.checkChanges(rawClasses, "classes")) {
rawClasses = rawClasses
.replace(startIdentifier, "")
.replace(endIdentifier, "")
.replaceAll("\"", "");

//Update current classes
this.informationController.setCurrentClasses(rawClasses.split(","));
LOGGER.trace("[SUBSTITUTE] Updated classes");
} else LOGGER.trace("[SUBSTITUTE] Classes did not change");
}

for (int week : weeks.keySet()) { //Iterate weeks
String requestUrl = "https://engelsburg.smmp.de/vertretungsplaene/eng/Stp_Upload/" + week + "/w/w00000.htm";
Expand Down Expand Up @@ -137,7 +140,7 @@ public void updateSubstitutes() {
//Remove the already used date elements, [2] - [8]
List<Element> substituteContentToParse = substitute.children();
for (Element paragraph : substituteContentToParse) {
if (!paragraph.tagName().equals("p") || paragraph.children().size() == 0) continue;
if (!paragraph.tagName().equals("p") || paragraph.children().isEmpty()) continue;

Element table = paragraph.child(0);
//If the tagName is not equal to "table", there will be information about the current date, --> [16]
Expand Down Expand Up @@ -179,7 +182,7 @@ public void updateSubstitutes() {
//If the row does not contain a className then this row is used to extend the text from
// the previous substitute, so it needs to be added to the latest substitute
String className = row.child(0).text();
if (substitutes.size() > 0 && !className.matches("(.*)[0-9](.*)")) {
if (!substitutes.isEmpty() && !className.matches("(.*)[0-9](.*)")) {
this.appendTextOnLastSubstitute(row, substitutes);
String appendedText = substitutes.get(substitutes.size() - 1).getText();

Expand Down Expand Up @@ -235,7 +238,7 @@ else if (entry.text().startsWith("Abwesende Klassen"))
} else {
//Update the current date
Elements days = paragraph.getElementsByTag("b");
if (days.size() > 0) {
if (!days.isEmpty()) {
rawDate = days.get(0).text();
dayAndMonth = rawDate.substring(0, rawDate.lastIndexOf('.'));
currentDate = this.parseDate(dayAndMonth, weeks.get(week));
Expand All @@ -254,7 +257,7 @@ else if (entry.text().startsWith("Abwesende Klassen"))
}

/**
* Function to create a substitute dto out of an html row.
* Function to create a substitute dto out of a html row.
*
* @param row with substitute information
* @param currentDate current date to assign to substitute
Expand Down

0 comments on commit 0884053

Please sign in to comment.