use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.
the class UntisCommonParser method parseMultipleMonitorDays.
void parseMultipleMonitorDays(SubstitutionSchedule v, Document doc, JSONObject data) throws JSONException, CredentialInvalidException, IOException {
if (doc.select(".mon_head").size() > 1) {
for (int j = 0; j < doc.select(".mon_head").size(); j++) {
Document doc2 = Document.createShell(doc.baseUri());
doc2.body().appendChild(doc.select(".mon_head").get(j).clone());
Element next = doc.select(".mon_head").get(j).nextElementSibling();
if (next != null && next.tagName().equals("center")) {
doc2.body().appendChild(next.select(".mon_title").first().clone());
if (next.select("table:has(tr.list)").size() > 0) {
doc2.body().appendChild(next.select("table:has(tr.list)").first());
}
if (next.select("table.info").size() > 0) {
doc2.body().appendChild(next.select("table.info").first());
}
} else if (doc.select(".mon_title").size() - 1 >= j) {
doc2.body().appendChild(doc.select(".mon_title").get(j).clone());
doc2.body().appendChild(doc.select("table:has(tr.list)").get(j).clone());
} else {
continue;
}
SubstitutionScheduleDay day = parseMonitorDay(doc2, data);
v.addDay(day);
}
} else if (doc.select(".mon_title").size() > 1) {
for (int j = 0; j < doc.select(".mon_title").size(); j++) {
Document doc2 = Document.createShell(doc.baseUri());
doc2.body().appendChild(doc.select(".mon_title").get(j).clone());
Element next = doc.select(".mon_title").get(j).nextElementSibling();
while (next != null && !next.tagName().equals("center")) {
doc2.body().appendChild(next);
next = doc.select(".mon_title").get(j).nextElementSibling();
}
SubstitutionScheduleDay day = parseMonitorDay(doc2, data);
v.addDay(day);
}
} else {
SubstitutionScheduleDay day = parseMonitorDay(doc, data);
v.addDay(day);
}
}
use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.
the class UntisInfoHeadlessParser method getSubstitutionSchedule.
@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
Document doc = Jsoup.parse(httpGet(url, data.optString(PARAM_ENCODING, null)));
doc.setBaseUri(url);
Elements dayElems = doc.select("#vertretung > p > b, #vertretung > b");
Elements frames = doc.select("frame[src*=w00]");
if (dayElems.size() == 0 && frames.size() > 0) {
// doc is embedded in frame
doc = Jsoup.parse(httpGet(frames.get(0).absUrl("src"), data.optString(PARAM_ENCODING, null)));
dayElems = doc.select("#vertretung > p > b, #vertretung > b");
}
final List<String> allClasses = getAllClasses();
if (dayElems.size() > 0) {
// untis-info days
for (Element dayElem : dayElems) {
SubstitutionScheduleDay day = new SubstitutionScheduleDay();
day.setLastChangeString("");
String date = dayElem.text();
day.setDateString(date);
day.setDate(ParserUtils.parseDate(date));
Element next;
if (dayElem.parent().tagName().equals("p")) {
next = dayElem.parent().nextElementSibling().nextElementSibling();
} else {
next = dayElem.parent().select("p").first().nextElementSibling();
}
parseDay(day, next, v, null, allClasses);
}
} else if (doc.select("tr:has(td[align=center]):gt(0)").size() > 0) {
// untis-subst table
parseSubstitutionTable(v, null, doc);
}
v.setClasses(allClasses);
v.setTeachers(getAllTeachers());
return v;
}
use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.
the class UntisInfoParser method parseTimetable.
private void parseTimetable(SubstitutionSchedule v, String lastChange, Document doc, String klasse, String weekName) throws JSONException {
v.setLastChange(ParserUtils.parseDateTime(lastChange));
LocalDate weekStart = DateTimeFormat.forPattern("d.M.yyyy").parseLocalDate(weekName);
Element table = doc.select("table").first();
List<SubstitutionScheduleDay> days = new ArrayList<>();
for (int i = 0; i < table.select("tr").first().select("td:gt(0)").size(); i++) {
LocalDate date = weekStart.plusDays(i);
SubstitutionScheduleDay day = null;
for (SubstitutionScheduleDay d : v.getDays()) {
if (d.getDate().equals(date)) {
day = d;
break;
}
}
if (day == null) {
day = new SubstitutionScheduleDay();
day.setDate(date);
v.addDay(day);
}
days.add(day);
}
Elements rows = table.select("> tbody > tr:gt(0)");
Map<Integer, String> lessons = new HashMap<>();
int i = 0;
int lessonCounter = 1;
while (i < rows.size()) {
Element cell = rows.get(i).select("td").first();
String lessonName = cell.text().trim();
if (lessonName.length() > 3) {
lessonName = String.valueOf(lessonCounter);
}
lessons.put(i, lessonName);
i += getRowspan(cell);
lessonCounter += 1;
}
// counts the number of columns that will be missing from each row due to a cell with colspan
Map<Integer, Integer> columnsToSkip = new HashMap<>();
for (int j = 0; j < rows.size(); j++) {
columnsToSkip.put(j, 0);
}
for (int col = 1; col < days.size(); col++) {
int row = 0;
while (row < rows.size()) {
Element cell = rows.get(row).select("> td").get(col - columnsToSkip.get(row));
String lesson = getTimetableLesson(cell, row, lessons);
days.get(col - 1).addAllSubstitutions(parseTimetableCell(cell, lesson, klasse, data.getJSONArray("cellFormat"), colorProvider));
for (int skippedRow = row + 1; skippedRow < row + getRowspan(cell); skippedRow++) {
columnsToSkip.put(skippedRow, columnsToSkip.get(skippedRow) + 1);
}
row += getRowspan(cell);
}
}
}
use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.
the class UntisMonitorParser method getSubstitutionSchedule.
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
loginResponse = new LoginHandler(scheduleData, credential, cookieProvider).handleLoginWithResponse(executor, cookieStore);
SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
JSONArray urls = scheduleData.getData().getJSONArray(PARAM_URLS);
String encoding = scheduleData.getData().optString(PARAM_ENCODING, null);
List<Document> docs = new ArrayList<>();
for (int i = 0; i < urls.length(); i++) {
JSONObject url = urls.getJSONObject(i);
final String urlStr = url.getString(SUBPARAM_URL);
for (String dateUrl : ParserUtils.handleUrlWithDateFormat(urlStr)) {
loadUrl(dateUrl, encoding, url.getBoolean(SUBPARAM_FOLLOWING), docs);
}
}
for (Document doc : docs) {
if (scheduleData.getData().has(PARAM_EMBEDDED_CONTENT_SELECTOR)) {
for (Element part : doc.select(scheduleData.getData().getString(PARAM_EMBEDDED_CONTENT_SELECTOR))) {
SubstitutionScheduleDay day = parseMonitorDay(part, scheduleData.getData());
v.addDay(day);
}
} else if (doc.title().contains("Untis") || doc.html().contains("<!--<title>Untis")) {
SubstitutionScheduleDay day = parseMonitorDay(doc, scheduleData.getData());
v.addDay(day);
}
if (scheduleData.getData().has(PARAM_LAST_CHANGE_SELECTOR) && doc.select(scheduleData.getData().getString(PARAM_LAST_CHANGE_SELECTOR)).size() > 0) {
String text = doc.select(scheduleData.getData().getString(PARAM_LAST_CHANGE_SELECTOR)).first().text();
String lastChange;
Pattern pattern = Pattern.compile("\\d\\d\\.\\d\\d\\.\\d\\d\\d\\d,? \\d\\d:\\d\\d");
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
lastChange = matcher.group();
} else {
lastChange = text;
}
v.setLastChangeString(lastChange);
v.setLastChange(ParserUtils.parseDateTime(lastChange));
}
}
if (scheduleData.getData().has(PARAM_WEBSITE)) {
v.setWebsite(scheduleData.getData().getString(PARAM_WEBSITE));
} else if (urls.length() == 1) {
v.setWebsite(urls.getJSONObject(0).getString("url"));
}
v.setClasses(getAllClasses());
v.setTeachers(getAllTeachers());
return v;
}
use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.
the class IndiwareDemoTest method demoTestXML.
@Test
public void demoTestXML() throws IOException, JSONException {
SubstitutionScheduleDay schedule = parser.parseIndiwareDay(Jsoup.parse(xml, "", Parser.xmlParser()), false);
verify(schedule);
}
Aggregations