Search in sources :

Example 26 with SubstitutionScheduleDay

use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.

the class SubstitutionScheduleDiff method filterDaysClass.

private void filterDaysClass(String theClass, Set<String> excludedSubjects, List<SubstitutionScheduleDay> days) {
    for (int i = 0; i < days.size(); i++) {
        SubstitutionScheduleDay day = days.get(i);
        SubstitutionScheduleDay filteredDay = day.clone();
        filteredDay.setSubstitutions(day.getSubstitutionsByClassAndExcludedSubject(theClass, excludedSubjects));
        days.set(i, filteredDay);
    }
}
Also used : SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay)

Example 27 with SubstitutionScheduleDay

use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.

the class NotCompatibleParser method getSubstitutionSchedule.

@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
    v.setLastChange(new LocalDateTime(2017, 10, 18, 12, 4));
    SubstitutionScheduleDay today = new SubstitutionScheduleDay();
    today.setDate(new LocalDate(2018, 1, 1));
    Substitution subst = new Substitution();
    subst.setLesson("0");
    subst.setClasses(new HashSet<>(getAllClasses()));
    subst.setType("siehe Nachrichten");
    subst.setDesc("Der Vertretungsplan kann von dieser Schule nicht mehr abgerufen werden. Genauere Informationen" + " findest du unter \"Nachrichten\".");
    subst.setColor("#F44336");
    today.addSubstitution(subst);
    today.addMessage("Aus technischen Gründen kann der Vertretungsplan dieser Schule mit dieser App nicht mehr " + "abgerufen werden. " + (scheduleData.getApi().equals("dsbmobile") ? "Als Alternative kannst du vorerst die offizielle " + "App \"DSBmobile\" nutzen. " : "") + "Falls Sie eine Lehrkraft oder Schulleiter/-in an der Schule sind, melden Sie sich " + "bitte unter info@vertretungsplan.me bei uns, um herauszufinden, wie der Plan wieder in die App " + "aufgenommen werden kann. Falls Sie die Pro-Version der App gekauft haben, können wir " + "Ihnen das Geld zurückerstatten, wenn Sie sich per E-Mail an info@vertretungsplan.me bei uns melden.");
    v.addDay(today);
    v.setClasses(getAllClasses());
    v.setTeachers(new ArrayList<String>());
    return v;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Substitution(me.vertretungsplan.objects.Substitution) SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) LocalDate(org.joda.time.LocalDate)

Example 28 with SubstitutionScheduleDay

use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.

the class SVPlanParser method parseSvPlanDay.

private void parseSvPlanDay(SubstitutionSchedule v, Element svp, Document doc) throws IOException, JSONException {
    SubstitutionScheduleDay day = new SubstitutionScheduleDay();
    if ((svp.select(".svp-plandatum-heute, .svp-plandatum-morgen, .Titel").size() > 0 || doc.title().startsWith("Vertretungsplan für "))) {
        setDate(svp, doc, day);
        final Elements tables = svp.select(".svp-tabelle, table:has(.Klasse)");
        if (tables.size() > 0) {
            Iterator<Element> iter = tables.iterator();
            while (iter.hasNext()) {
                Element table = iter.next();
                if (!table.hasClass("svp-tabelle") && table.select("> tbody > tr > td.Klasse").size() == 0) {
                    iter.remove();
                }
            }
            Elements rows = tables.select("tr");
            String lastLesson = "";
            String lastClass = "";
            for (Element row : rows) {
                if ((doc.select(".svp-header").size() > 0 && row.hasClass("svp-header")) || row.select("th").size() > 0 || row.text().trim().equals("")) {
                    continue;
                }
                Substitution substitution = new Substitution();
                for (Element column : row.select("td")) {
                    String type = column.className();
                    if (!hasData(column.text())) {
                        if ((type.startsWith("svp-stunde") || type.startsWith("Stunde")) && hasData(lastLesson)) {
                            substitution.setLesson(lastLesson);
                        } else if ((type.startsWith("svp-klasse") || type.startsWith("Klasse")) && hasData(lastClass) && data.optBoolean(PARAM_REPEAT_CLASS, true)) {
                            substitution.getClasses().addAll(getClasses(lastClass));
                        }
                        continue;
                    }
                    if (type.startsWith("svp-stunde") || type.startsWith("Stunde")) {
                        substitution.setLesson(column.text());
                        lastLesson = column.text();
                    } else if (type.startsWith("svp-klasse") || type.startsWith("Klasse")) {
                        substitution.getClasses().addAll(getClasses(column.text()));
                        lastClass = column.text();
                    } else if (type.startsWith("svp-esfehlt") || type.startsWith("Lehrer")) {
                        if (!data.optBoolean(PARAM_EXCLUDE_TEACHERS)) {
                            substitution.setPreviousTeacher(column.text());
                        }
                    } else if (type.startsWith("svp-esvertritt") || type.startsWith("Vertretung")) {
                        if (!data.optBoolean(PARAM_EXCLUDE_TEACHERS)) {
                            substitution.setTeacher(column.text().replaceAll(" \\+$", ""));
                        }
                    } else if (type.startsWith("svp-fach") || type.startsWith("Fach")) {
                        substitution.setSubject(column.text());
                    } else if (type.startsWith("svp-bemerkung") || type.startsWith("Anmerkung")) {
                        substitution.setDesc(column.text());
                        String recognizedType = recognizeType(column.text());
                        substitution.setType(recognizedType);
                        substitution.setColor(colorProvider.getColor(recognizedType));
                    } else if (type.startsWith("svp-raum") || type.startsWith("Raum")) {
                        substitution.setRoom(column.text());
                    }
                }
                if (substitution.getType() == null) {
                    substitution.setType("Vertretung");
                    substitution.setColor(colorProvider.getColor("Vertretung"));
                }
                day.addSubstitution(substitution);
            }
        }
        if (svp.select(".LehrerVerplant").size() > 0) {
            day.addMessage("<b>Verplante Lehrer:</b> " + svp.select(".LehrerVerplant").text());
        }
        if (svp.select(".Abwesenheiten").size() > 0) {
            day.addMessage("<b>Abwesenheiten:</b> " + svp.select(".Abwesenheiten").text());
        }
        if (svp.select("h2:contains(Mitteilungen)").size() > 0) {
            Element h2 = svp.select("h2:contains(Mitteilungen)").first();
            Element sibling = h2.nextElementSibling();
            while (sibling != null && sibling.tagName().equals("p")) {
                for (String nachricht : TextNode.createFromEncoded(sibling.html(), null).getWholeText().split("<br />\\s*<br />")) {
                    if (hasData(nachricht))
                        day.addMessage(nachricht);
                }
                sibling = sibling.nextElementSibling();
            }
        } else if (svp.select(".Mitteilungen").size() > 0) {
            for (Element p : svp.select(".Mitteilungen")) {
                for (String nachricht : TextNode.createFromEncoded(p.html(), null).getWholeText().split("<br />\\s*<br />")) {
                    if (hasData(nachricht))
                        day.addMessage(nachricht);
                }
            }
        }
        v.addDay(day);
    } else {
        throw new IOException("keine SVPlan-Tabelle gefunden");
    }
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) Element(org.jsoup.nodes.Element) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) IOException(java.io.IOException) Elements(org.jsoup.select.Elements)

Example 29 with SubstitutionScheduleDay

use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.

the class TurboVertretungParser method parseTurboVertretungDay.

private void parseTurboVertretungDay(SubstitutionSchedule v, Document doc) {
    SubstitutionScheduleDay day = new SubstitutionScheduleDay();
    String date = doc.select(".Titel").text().replaceFirst("Vertretungsplan( für)? ", "");
    day.setDate(DateTimeFormat.forPattern("EEEE, d. MMMM yyyy").withLocale(Locale.GERMAN).parseLocalDate(date));
    String lastChange = doc.select(".Stand").text();
    day.setLastChange(ParserUtils.parseDateTime(lastChange));
    if (doc.text().contains("Kein Vertretungsplan")) {
        v.addDay(day);
        return;
    }
    if (doc.select(".LehrerFrueher").size() > 0) {
        day.addMessage(doc.select(".LehrerFrueherLabel").text() + "\n" + doc.select(".LehrerFrueher").text());
    }
    if (doc.select(".LehrerVerplant").size() > 0) {
        day.addMessage(doc.select(".LehrerVerplantLabel").text() + "\n" + doc.select(".LehrerVerplant").text());
    }
    if (doc.select(".Abwesenheiten-Klassen").size() > 0) {
        day.addMessage(doc.select(".Abwesenheiten-KlassenLabel").text() + "\n" + doc.select(".Abwesenheiten-Klassen").text());
    }
    if (doc.select(".Abwesenheiten").size() > 0) {
        day.addMessage(doc.select(".AbwesenheitenLabel").text() + "\n" + doc.select(".Abwesenheiten").text());
    }
    Element table = doc.select("table").first();
    for (Element row : table.select("tr:has(td)")) {
        if (row.select(".Klasseleer").size() > 0)
            continue;
        Substitution substitution = new Substitution();
        substitution.setLesson(row.select(query("Stunde")).text());
        substitution.setPreviousTeacher(row.select(query("Lehrer")).text());
        substitution.setTeacher(row.select(query("Vertretung")).text());
        substitution.setClasses(new HashSet<>(Arrays.asList(row.select(query("Klasse")).text().split(" "))));
        substitution.setSubject(row.select(query("Fach")).text());
        substitution.setDesc(row.select(query("Anmerkung")).text());
        substitution.setRoom(row.select(query("Raum")).text());
        String type = recognizeType(row.select(query("Anmerkung")).text());
        if (type == null)
            type = "Vertretung";
        substitution.setType(type);
        substitution.setColor(colorProvider.getColor(type));
        day.addSubstitution(substitution);
    }
    v.addDay(day);
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) Element(org.jsoup.nodes.Element) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay)

Example 30 with SubstitutionScheduleDay

use of me.vertretungsplan.objects.SubstitutionScheduleDay in project substitution-schedule-parser by vertretungsplanme.

the class UntisInfoParser method parseSubstitutionDays.

void parseSubstitutionDays(SubstitutionSchedule v, String lastChange, Document doc, String klasse, List<String> allClasses) throws JSONException, CredentialInvalidException, IOException {
    Elements days = doc.select("#vertretung > p > b, #vertretung > b, p:has(a[href^=#]) > b");
    if (days.size() > 0) {
        for (Element dayElem : days) {
            SubstitutionScheduleDay day = new SubstitutionScheduleDay();
            day.setLastChangeString(lastChange);
            day.setLastChange(ParserUtils.parseDateTime(lastChange));
            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, klasse, allClasses);
        }
    } else if (doc.select("tr:has(td[align=center]):gt(0)").size() > 0) {
        parseSubstitutionTable(v, null, doc);
        v.setLastChangeString(lastChange);
        v.setLastChange(ParserUtils.parseDateTime(lastChange));
    }
}
Also used : Element(org.jsoup.nodes.Element) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) Elements(org.jsoup.select.Elements)

Aggregations

SubstitutionScheduleDay (me.vertretungsplan.objects.SubstitutionScheduleDay)34 LocalDate (org.joda.time.LocalDate)15 Substitution (me.vertretungsplan.objects.Substitution)14 SubstitutionSchedule (me.vertretungsplan.objects.SubstitutionSchedule)14 Test (org.junit.Test)14 LocalDateTime (org.joda.time.LocalDateTime)12 Element (org.jsoup.nodes.Element)10 Matcher (java.util.regex.Matcher)6 Document (org.jsoup.nodes.Document)6 Elements (org.jsoup.select.Elements)6 Pattern (java.util.regex.Pattern)5 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 JSONObject (org.json.JSONObject)3 JSONArray (org.json.JSONArray)2 HashSet (java.util.HashSet)1 AdditionalInfo (me.vertretungsplan.objects.AdditionalInfo)1 SubstitutionScheduleData (me.vertretungsplan.objects.SubstitutionScheduleData)1 TextNode (org.jsoup.nodes.TextNode)1