Search in sources :

Example 1 with NoAuthenticationData

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

the class ESchoolParser method getSubstitutionSchedule.

@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    if (!(scheduleData.getAuthenticationData() instanceof NoAuthenticationData) && (credential == null || !(credential instanceof PasswordCredential) || ((PasswordCredential) credential).getPassword() == null || ((PasswordCredential) credential).getPassword().isEmpty())) {
        throw new IOException("no login");
    }
    List<NameValuePair> nvps = new ArrayList<>();
    nvps.add(new BasicNameValuePair("wp", scheduleData.getData().getString(PARAM_ID)));
    nvps.add(new BasicNameValuePair("go", "vplan"));
    nvps.add(new BasicNameValuePair("content", "x14"));
    nvps.add(new BasicNameValuePair("sortby", "S"));
    String url = BASE_URL + "?" + URLEncodedUtils.format(nvps, "UTF-8");
    Document doc = Jsoup.parse(httpGet(url, ENCODING));
    if (doc.select("form[name=loginform]").size() > 0 && scheduleData.getAuthenticationData() instanceof PasswordAuthenticationData) {
        // Login required
        List<NameValuePair> formParams = new ArrayList<>();
        formParams.add(new BasicNameValuePair("password", ((PasswordCredential) credential).getPassword()));
        formParams.add(new BasicNameValuePair("login", ""));
        doc = Jsoup.parse(httpPost(url, ENCODING, formParams));
        if (doc.select("font[color=red]").text().contains("fehlgeschlagen")) {
            throw new CredentialInvalidException();
        }
    }
    SubstitutionSchedule schedule = parseESchoolSchedule(doc);
    return schedule;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) NoAuthenticationData(me.vertretungsplan.objects.authentication.NoAuthenticationData) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) PasswordCredential(me.vertretungsplan.objects.credential.PasswordCredential) ArrayList(java.util.ArrayList) PasswordAuthenticationData(me.vertretungsplan.objects.authentication.PasswordAuthenticationData) CredentialInvalidException(me.vertretungsplan.exception.CredentialInvalidException) IOException(java.io.IOException) Document(org.jsoup.nodes.Document)

Example 2 with NoAuthenticationData

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

the class Sample method main.

public static void main(String[] args) throws JSONException, IOException, CredentialInvalidException {
    SubstitutionScheduleData data = new SubstitutionScheduleData();
    data.setType(SubstitutionSchedule.Type.STUDENT);
    data.setApi("untis-monitor");
    data.setAuthenticationData(new NoAuthenticationData());
    data.setData(new JSONObject("{\n" + "         \"classes\": [\n" + "           \"05a\",\"05b\",\"05c\",\"05d\",\"05e\",\"05f\",\"05g\",\n" + "           \"06a\",\"06b\",\"06c\",\"06d\",\"06e\",\"06f\",\"06g\",\n" + "           \"07a\",\"07b\",\"07c\",\"07d\",\"07e\",\"07f\",\"07g\",\n" + "           \"08a\",\"08b\",\"08c\",\"08d\",\"08e\",\"08f\",\"08g\",\n" + "           \"09a\",\"09b\",\"09c\",\"09d\",\"09e\",\"09f\",\"09g\",\n" + "           \"Ea\",\"Eb\",\"Ec\",\"Ed\",\"Ee\",\"Ef\",\n" + "           \"Q1a\",\"Q1b\",\"Q1c\",\"Q1d\",\"Q1e\",\"Q1f\",\"Q1g\",\"Q1h\",\"Q1i\",\"Q1j\",\n" + "           \"Q2a\",\"Q2b\",\"Q2c\",\"Q2d\",\"Q2e\",\"Q2f\",\"Q2g\",\"Q2h\",\"Q2i\",\"Q2j\" \n" + "        ],\n" + "         \"class_in_extra_line\": true,\n" + "         \"website\": \"http://vertretung.lornsenschule.de/schueler/subst_001.htm\",\n" + "         \"stand_links\": true,\n" + "         \"urls\": [\n" + "           {\n" + "             \"following\": false,\n" + "             \"url\": \"http://vertretung.lornsenschule.de/schueler/f1/subst_001.htm\" \n" + "          },\n" + "           {\n" + "             \"following\": false,\n" + "             \"url\": \"http://vertretung.lornsenschule.de/schueler/f2/subst_001.htm\" \n" + "          } \n" + "        ],\n" + "         \"encoding\": \"ISO-8859-1\",\n" + "         \"columns\": [\n" + "           \"lesson\",\"type\",\"subject\",\"previousSubject\",\"room\",\"desc\" \n" + "        ] \n" + "      }"));
    data.getAdditionalInfos().add("winter-sh");
    SubstitutionSchedule schedule = ParserUtil.parseSubstitutionSchedule(data);
    System.out.println(schedule);
}
Also used : SubstitutionScheduleData(me.vertretungsplan.objects.SubstitutionScheduleData) JSONObject(org.json.JSONObject) NoAuthenticationData(me.vertretungsplan.objects.authentication.NoAuthenticationData) SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule)

Aggregations

SubstitutionSchedule (me.vertretungsplan.objects.SubstitutionSchedule)2 NoAuthenticationData (me.vertretungsplan.objects.authentication.NoAuthenticationData)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CredentialInvalidException (me.vertretungsplan.exception.CredentialInvalidException)1 SubstitutionScheduleData (me.vertretungsplan.objects.SubstitutionScheduleData)1 PasswordAuthenticationData (me.vertretungsplan.objects.authentication.PasswordAuthenticationData)1 PasswordCredential (me.vertretungsplan.objects.credential.PasswordCredential)1 NameValuePair (org.apache.http.NameValuePair)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 JSONObject (org.json.JSONObject)1 Document (org.jsoup.nodes.Document)1