
me.vertretungsplan.parser.CSVParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parser Show documentation
Show all versions of parser Show documentation
Java library for parsing schools' substitution schedules. Supports multiple different systems mainly used in the German-speaking countries.
/*
* substitution-schedule-parser - Java library for parsing schools' substitution schedules
* Copyright (c) 2016 Johan v. Forstner
*
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.vertretungsplan.parser;
import me.vertretungsplan.exception.CredentialInvalidException;
import me.vertretungsplan.objects.Substitution;
import me.vertretungsplan.objects.SubstitutionSchedule;
import me.vertretungsplan.objects.SubstitutionScheduleData;
import me.vertretungsplan.objects.SubstitutionScheduleDay;
import org.apache.http.client.fluent.Request;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Generischer Parser für Vertretungspläne im CSV-Format
* Beispiel: http://czg.noxxi.de/vp.pl?/csv
*/
public class CSVParser extends BaseParser {
private JSONObject data;
public CSVParser(SubstitutionScheduleData scheduleData, CookieProvider cookieProvider) {
super(scheduleData, cookieProvider);
data = scheduleData.getData();
}
@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException,
CredentialInvalidException {
new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
String url = data.getString("url");
String response = executor.execute(Request.Get(url)).returnContent().asString();
SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);
String[] lines = response.split("\n");
String separator = data.getString("separator");
for (int i = data.optInt("skipLines", 0); i getAllClasses() throws IOException, JSONException {
if (data.has("classesUrl")) {
String url = data.getString("classesUrl");
String response = executor.execute(Request.Get(url)).returnContent().asString();
List classes = new ArrayList<>();
for (String string:response.split("\n")) {
classes.add(string.trim());
}
return classes;
} else {
JSONArray classesJson = data.getJSONArray("classes");
List classes = new ArrayList<>();
for (int i = 0; i < classesJson.length(); i++) {
classes.add(classesJson.getString(i));
}
return classes;
}
}
@Override
public List getAllTeachers() {
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy