mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 03:06:50 -06:00
API fixes (#136)
This commit is contained in:
parent
81d177c270
commit
7b7be1eef1
@ -62,6 +62,7 @@ public class Client {
|
||||
return;
|
||||
}
|
||||
|
||||
clearCookies();
|
||||
this.symbol = new Login(this).login(email, password, symbol);
|
||||
logger.info("Login successful on {} at {}", getHost(), new Date());
|
||||
}
|
||||
@ -87,6 +88,10 @@ public class Client {
|
||||
return cookies.getItems();
|
||||
}
|
||||
|
||||
public void clearCookies() {
|
||||
cookies = new Cookies();
|
||||
}
|
||||
|
||||
String getHost() {
|
||||
return host;
|
||||
}
|
||||
@ -216,7 +221,7 @@ public class Client {
|
||||
}
|
||||
|
||||
if ("Błąd strony".equals(title)) {
|
||||
throw new NotLoggedInErrorException(title + " " + doc.selectFirst("body") + ", status: " + code);
|
||||
throw new NotLoggedInErrorException(title + " " + doc.body() + ", status: " + code);
|
||||
}
|
||||
|
||||
return doc;
|
||||
|
@ -5,6 +5,8 @@ import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.parser.Parser;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -21,6 +23,8 @@ public class Login {
|
||||
|
||||
private Client client;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Login.class);
|
||||
|
||||
public Login(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
@ -29,7 +33,8 @@ public class Login {
|
||||
Document certDoc = sendCredentials(email, password);
|
||||
|
||||
if ("Błąd".equals(certDoc.title())) {
|
||||
throw new NotLoggedInErrorException(certDoc.selectFirst("body").text());
|
||||
client.clearCookies();
|
||||
throw new NotLoggedInErrorException(certDoc.body().text());
|
||||
}
|
||||
|
||||
return sendCertificate(certDoc, symbol);
|
||||
@ -88,6 +93,7 @@ public class Login {
|
||||
String title = targetDoc.title();
|
||||
|
||||
if ("Working...".equals(title)) { // on adfs login
|
||||
logger.info("ADFS login");
|
||||
title = sendCertData(targetDoc).title();
|
||||
}
|
||||
|
||||
@ -96,6 +102,7 @@ public class Login {
|
||||
}
|
||||
|
||||
if (!"Uonet+".equals(title)) {
|
||||
logger.debug("Login failed. Body: {}", targetDoc.body());
|
||||
throw new LoginErrorException("Expected page title `UONET+`, got " + title);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package io.github.wulkanowy.api.timetable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -13,8 +15,8 @@ import io.github.wulkanowy.api.VulcanException;
|
||||
import io.github.wulkanowy.api.generic.Lesson;
|
||||
import io.github.wulkanowy.api.generic.Week;
|
||||
|
||||
import static io.github.wulkanowy.api.DateTimeUtilsKt.getFormattedDate;
|
||||
import static io.github.wulkanowy.api.DateTimeUtilsKt.getDateAsTick;
|
||||
import static io.github.wulkanowy.api.DateTimeUtilsKt.getFormattedDate;
|
||||
|
||||
public class Timetable {
|
||||
|
||||
@ -22,6 +24,8 @@ public class Timetable {
|
||||
|
||||
private SnP snp;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Timetable.class);
|
||||
|
||||
public Timetable(SnP snp) {
|
||||
this.snp = snp;
|
||||
}
|
||||
@ -45,8 +49,13 @@ public class Timetable {
|
||||
|
||||
private List<TimetableDay> getDays(Elements tableHeaderCells) {
|
||||
List<TimetableDay> days = new ArrayList<>();
|
||||
int numberOfDays = tableHeaderCells.size();
|
||||
|
||||
for (int i = 2; i < 7; i++) {
|
||||
if (numberOfDays > 7) {
|
||||
logger.info("Number of days: {}", numberOfDays);
|
||||
}
|
||||
|
||||
for (int i = 2; i < numberOfDays; i++) {
|
||||
String[] dayHeaderCell = tableHeaderCells.get(i).html().split("<br>");
|
||||
|
||||
TimetableDay day = new TimetableDay();
|
||||
@ -127,6 +136,11 @@ public class Timetable {
|
||||
private void addLessonInfoFromElement(Lesson lesson, Element e) {
|
||||
Elements spans = e.select("span");
|
||||
|
||||
if (spans.isEmpty()) {
|
||||
logger.warn("Lesson span is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
addTypeInfo(lesson, spans);
|
||||
addNormalLessonInfo(lesson, spans);
|
||||
addChangesInfo(lesson, spans);
|
||||
@ -213,6 +227,10 @@ public class Timetable {
|
||||
}
|
||||
|
||||
private String[] getLessonAndGroupInfoFromSpan(Element span) {
|
||||
if (!span.text().contains("[")) {
|
||||
return new String[] {span.text(), ""};
|
||||
}
|
||||
|
||||
String[] subjectNameArray = span.text().split(" ");
|
||||
String groupName = subjectNameArray[subjectNameArray.length - 1];
|
||||
|
||||
|
@ -156,6 +156,7 @@ public class TimetableTest extends StudentAndParentTestCase {
|
||||
Assert.assertEquals("poprzednio: Wychowanie fizyczne", full.getWeekTable().getDay(4).getLesson(2).getDescription());
|
||||
Assert.assertEquals("egzamin", full.getWeekTable().getDay(3).getLesson(0).getDescription());
|
||||
Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription());
|
||||
Assert.assertEquals("poprzednio: Zajęcia z wychowawcą", full.getWeekTable().getDay(4).getLesson(5).getDescription());
|
||||
Assert.assertEquals("opis w uwadze bez klasy w spanie", full.getWeekTable().getDay(4).getLesson(4).getDescription());
|
||||
Assert.assertEquals("", holidays.getWeekTable().getDay(3).getLesson(3).getDescription());
|
||||
}
|
||||
|
@ -364,7 +364,20 @@
|
||||
<span></span>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div>
|
||||
<span class="">Tworzenie i administrowanie bazami danych [zaw2]</span>
|
||||
<span class=""></span>
|
||||
<span class=""></span>
|
||||
<span class=""></span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="x-treelabel-ppl x-treelabel-inv">Zajęcia z wychowawcą</span>
|
||||
<span class="x-treelabel-ppl x-treelabel-inv">Małgorzata Kowal</span>
|
||||
<span class="x-treelabel-ppl x-treelabel-inv">43</span>
|
||||
<span class="x-treelabel-rlz">(zmiana organizacji zajęć)</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user