use of me.vertretungsplan.objects.SubstitutionSchedule in project substitution-schedule-parser by vertretungsplanme.
the class IndiwareParser 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<String> docs = new ArrayList<>();
SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
int successfulSchedules = 0;
IOException lastException = null;
for (int i = 0; i < urls.length(); i++) {
if (urls.optJSONObject(i) != null) {
try {
JSONObject obj = urls.getJSONObject(i);
String url = obj.getString("url");
if (obj.has("postData")) {
JSONObject postParams = obj.getJSONObject("postData");
List<NameValuePair> nvps = new ArrayList<>();
for (String name : JSONObject.getNames(postParams)) {
String value = postParams.getString(name);
nvps.add(new BasicNameValuePair(name, value));
}
docs.add(httpPost(url, encoding, nvps));
successfulSchedules++;
}
} catch (IOException e) {
lastException = e;
}
} else {
for (String url : ParserUtils.handleUrlWithDateFormat(urls.getString(i))) {
try {
docs.add(httpGet(url, encoding));
successfulSchedules++;
} catch (IOException e) {
lastException = e;
}
}
}
}
if (successfulSchedules == 0 && lastException != null) {
throw lastException;
}
successfulSchedules = 0;
lastException = null;
for (String response : docs) {
try {
parseIndiwarePage(v, response);
successfulSchedules++;
} catch (IOException e) {
lastException = e;
}
}
if (successfulSchedules == 0 && lastException != null) {
throw lastException;
}
v.setWebsite(urls.getString(0));
v.setClasses(getAllClasses());
v.setTeachers(getAllTeachers());
return v;
}
use of me.vertretungsplan.objects.SubstitutionSchedule in project substitution-schedule-parser by vertretungsplanme.
the class SVPlanParser method getSubstitutionSchedule.
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<>();
int successfulSchedules = 0;
IOException lastException = null;
for (int i = 0; i < urls.length(); i++) {
String url;
if (urls.get(i) instanceof JSONObject) {
// backwards compatibility
final JSONObject obj = urls.getJSONObject(i);
url = obj.getString("url");
if (obj.has("postData")) {
JSONObject postParams = obj.getJSONObject("postData");
List<NameValuePair> nvps = new ArrayList<>();
for (String name : JSONObject.getNames(postParams)) {
String value = postParams.getString(name);
nvps.add(new BasicNameValuePair(name, value));
}
try {
docs.add(Jsoup.parse(httpPost(url, encoding, nvps).replace(" ", "")));
successfulSchedules++;
} catch (IOException e) {
lastException = e;
}
} else {
try {
docs.add(Jsoup.parse(httpGet(url, encoding).replace(" ", "")));
successfulSchedules++;
} catch (IOException e) {
lastException = e;
}
}
} else {
url = urls.getString(i);
try {
docs.add(Jsoup.parse(httpGet(url, encoding).replace(" ", "")));
successfulSchedules++;
} catch (IOException e) {
lastException = e;
}
}
}
if (successfulSchedules == 0 && lastException != null) {
throw lastException;
}
SubstitutionSchedule v = parseSVPlanSchedule(docs);
return v;
}
use of me.vertretungsplan.objects.SubstitutionSchedule in project substitution-schedule-parser by vertretungsplanme.
the class SVPlanParser method parseSVPlanSchedule.
@NotNull
SubstitutionSchedule parseSVPlanSchedule(List<Document> docs) throws IOException, JSONException {
SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
for (Document doc : docs) {
if (doc.select(".svp").size() > 0) {
for (Element svp : doc.select(".svp")) {
parseSvPlanDay(v, svp, doc);
}
} else if (doc.select(".Trennlinie").size() > 0) {
Element div = new Element(Tag.valueOf("div"), "");
for (Node node : doc.body().childNodesCopy()) {
if (node instanceof Element && ((Element) node).hasClass("Trennlinie") && div.select("table").size() > 0) {
parseSvPlanDay(v, div, doc);
div = new Element(Tag.valueOf("div"), "");
} else {
div.appendChild(node);
}
}
parseSvPlanDay(v, div, doc);
} else {
parseSvPlanDay(v, doc, doc);
}
}
v.setClasses(getAllClasses());
v.setTeachers(getAllTeachers());
return v;
}
use of me.vertretungsplan.objects.SubstitutionSchedule 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.SubstitutionSchedule in project substitution-schedule-parser by vertretungsplanme.
the class IndiwareMobileParser method getSubstitutionSchedule.
@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
String baseurl = data.getString(PARAM_BASEURL) + "/";
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 filePrefix = scheduleData.getType() == SubstitutionSchedule.Type.TEACHER ? "PlanLe" : "PlanKl";
String url = baseurl + "mobdaten/" + filePrefix + dateStr + "" + ".xml?_=" + System.currentTimeMillis();
HttpResponseException lastException = null;
try {
String xml = httpGet(url, "UTF-8");
Document doc = Jsoup.parse(xml, url, Parser.xmlParser());
if (doc.select("kopf datei").text().equals(filePrefix + dateStr + ".xml")) {
docs.add(doc);
}
} catch (HttpResponseException e) {
lastException = e;
}
if (docs.size() == 0 && lastException != null) {
throw lastException;
}
}
SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
for (Document doc : docs) {
v.addDay(parseDay(doc, colorProvider, scheduleData));
}
v.setClasses(getAllClasses());
v.setTeachers(getAllTeachers());
v.setWebsite(baseurl + "plankl.html");
return v;
}
Aggregations