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;
}
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);
}
Aggregations