Search in sources :

Example 21 with SubstitutionSchedule

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

the class IndiwareStundenplan24Parser method getSubstitutionSchedule.

@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    String baseurl;
    if (data.has("schoolNumber")) {
        baseurl = "https://www.stundenplan24.de/" + data.getString("schoolNumber") + "/vplan/";
        if (credential == null || !(credential instanceof UserPasswordCredential)) {
            throw new IOException("no login");
        }
        String login = ((UserPasswordCredential) credential).getUsername();
        String password = ((UserPasswordCredential) credential).getPassword();
        executor.auth(login, password);
    } else {
        baseurl = data.getString("baseurl") + "/";
        new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
    }
    List<Document> docs = new ArrayList<>();
    for (int i = 0; i < MAX_DAYS; i++) {
        LocalDate date = LocalDate.now().plusDays(i);
        String dateStr = DateTimeFormat.forPattern("yyyyMMdd").print(date);
        String url = baseurl + "vdaten/VplanKl" + dateStr + ".xml?_=" + System.currentTimeMillis();
        try {
            String xml = httpGet(url, ENCODING);
            Document doc = Jsoup.parse(xml, url, Parser.xmlParser());
            if (doc.select("kopf datei").text().equals("VplanKl" + dateStr + ".xml")) {
                docs.add(doc);
            }
        } catch (HttpResponseException e) {
            if (e.getStatusCode() != 404 && e.getStatusCode() != 300)
                throw e;
        }
    }
    SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
    for (Document doc : docs) {
        v.addDay(parseIndiwareDay(doc, false));
    }
    v.setWebsite(baseurl);
    v.setClasses(getAllClasses());
    v.setTeachers(getAllTeachers());
    return v;
}
Also used : SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) ArrayList(java.util.ArrayList) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) UserPasswordCredential(me.vertretungsplan.objects.credential.UserPasswordCredential) Document(org.jsoup.nodes.Document) LocalDate(org.joda.time.LocalDate)

Example 22 with SubstitutionSchedule

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

the class LegionBoardParser method getSubstitutionSchedule.

public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    final SubstitutionSchedule substitutionSchedule = SubstitutionSchedule.fromData(scheduleData);
    substitutionSchedule.setClasses(getAllClasses());
    substitutionSchedule.setTeachers(getAllTeachers());
    substitutionSchedule.setWebsite(website);
    final JSONArray changes = getChanges();
    final JSONArray courses = getCourses();
    final JSONArray teachers = getTeachers();
    parseLegionBoard(substitutionSchedule, changes, courses, teachers);
    return substitutionSchedule;
}
Also used : SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) JSONArray(org.json.JSONArray)

Example 23 with SubstitutionSchedule

use of me.vertretungsplan.objects.SubstitutionSchedule 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 24 with SubstitutionSchedule

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

the class TurboVertretungParser method getSubstitutionSchedule.

@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    // 
    new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
    JSONArray urls = data.getJSONArray(PARAM_URLS);
    String encoding = data.optString(PARAM_ENCODING, null);
    List<Document> docs = new ArrayList<>();
    SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
    for (int i = 0; i < urls.length(); i++) {
        String url;
        if (urls.get(i) instanceof JSONObject) {
            // backwards compatibility
            url = urls.getJSONObject(i).getString("url");
        } else {
            url = urls.getString(i);
        }
        loadUrl(url, encoding, docs);
    }
    for (Document doc : docs) {
        String html = doc.body().html();
        String[] parts = html.split("<p class=\"Titel\">");
        for (int i = 1; i < parts.length; i++) {
            Document partDoc = Jsoup.parse("<p class=\"Titel\">" + parts[i]);
            parseTurboVertretungDay(v, partDoc);
        }
    }
    v.setClasses(getAllClasses());
    v.setTeachers(getAllTeachers());
    return v;
}
Also used : JSONObject(org.json.JSONObject) SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) JSONArray(org.json.JSONArray) Document(org.jsoup.nodes.Document)

Example 25 with SubstitutionSchedule

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

the class UntisSubstitutionParser method getSubstitutionSchedule.

@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
    String encoding = data.optString(PARAM_ENCODING, null);
    SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
    int successfulSchedules = 0;
    HttpResponseException lastExceptionSchedule = null;
    for (String baseUrl : ParserUtils.handleUrlsWithDateFormat(urls)) {
        try {
            Document doc = Jsoup.parse(this.httpGet(baseUrl, encoding));
            Elements classes = doc.select("td a");
            String lastChange = doc.select("td[align=right]:not(:has(b))").text();
            int successfulClasses = 0;
            HttpResponseException lastExceptionClass = null;
            for (Element klasse : classes) {
                try {
                    Document classDoc = Jsoup.parse(httpGet(baseUrl.substring(0, baseUrl.lastIndexOf("/")) + "/" + klasse.attr("href"), encoding));
                    parseSubstitutionTable(v, lastChange, classDoc, klasse.text());
                    successfulClasses++;
                } catch (HttpResponseException e) {
                    lastExceptionClass = e;
                }
            }
            if (successfulClasses == 0 && lastExceptionClass != null) {
                throw lastExceptionClass;
            }
            successfulSchedules++;
        } catch (HttpResponseException e) {
            lastExceptionSchedule = e;
        }
    }
    if (successfulSchedules == 0 && lastExceptionSchedule != null) {
        throw lastExceptionSchedule;
    }
    if (data.has(PARAM_WEBSITE)) {
        v.setWebsite(data.getString(PARAM_WEBSITE));
    } else {
        v.setWebsite(urls.get(0));
    }
    v.setClasses(getAllClasses());
    v.setTeachers(getAllTeachers());
    return v;
}
Also used : SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) Element(org.jsoup.nodes.Element) HttpResponseException(org.apache.http.client.HttpResponseException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

SubstitutionSchedule (me.vertretungsplan.objects.SubstitutionSchedule)31 Document (org.jsoup.nodes.Document)15 SubstitutionScheduleDay (me.vertretungsplan.objects.SubstitutionScheduleDay)14 LocalDate (org.joda.time.LocalDate)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)9 LocalDateTime (org.joda.time.LocalDateTime)9 Substitution (me.vertretungsplan.objects.Substitution)8 IOException (java.io.IOException)6 JSONArray (org.json.JSONArray)6 JSONObject (org.json.JSONObject)6 Element (org.jsoup.nodes.Element)6 HttpResponseException (org.apache.http.client.HttpResponseException)4 NameValuePair (org.apache.http.NameValuePair)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 NotNull (org.jetbrains.annotations.NotNull)3 Elements (org.jsoup.select.Elements)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 CredentialInvalidException (me.vertretungsplan.exception.CredentialInvalidException)2