Blackboard Event support
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
package de.sebse.fuplanner.services.kvv;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.MatchResult;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Event;
|
import de.sebse.fuplanner.services.kvv.types.Event;
|
||||||
import de.sebse.fuplanner.services.kvv.types.EventList;
|
import de.sebse.fuplanner.services.kvv.types.EventList;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
@@ -83,6 +89,76 @@ public class ModulesEvents extends PartModules<EventList> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void upgradeBB(String ID, NetworkCallback<EventList> callback, NetworkErrorCallback errorCallback) {
|
protected void upgradeBB(String ID, NetworkCallback<EventList> callback, NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
||||||
|
errorCallback.onError(new NetworkError(101414, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.mList.find(ID, module -> {
|
||||||
|
log.d(module.lvNumber.size(), module.lvNumber);
|
||||||
|
log.d(module.lvNumber.iterator().next());
|
||||||
|
super.head(String.format("https://www.fu-berlin.de/vv/de/search?utf8=✓&query=%s", module.lvNumber.iterator().next()), null, response -> {
|
||||||
|
String location = response.getHeaders().get("Location");
|
||||||
|
if (location == null) {
|
||||||
|
// Events not available
|
||||||
callback.onResponse(new EventList());
|
callback.onResponse(new EventList());
|
||||||
|
//errorCallback.onError(new NetworkError(101410, 403, "Cannot get events!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String group;
|
||||||
|
try {
|
||||||
|
group = Regex.regex("lv/([0-9]+)\\?", location);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
errorCallback.onError(new NetworkError(101410, 400, "Cannot get events!"));
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.get(String.format("https://www.fu-berlin.de/vv/de/lv/%s", group), null, response1 -> {
|
||||||
|
String body = response1.getParsed();
|
||||||
|
log.d(response1.getHeaders().get("Location"));
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101411, 400, "Cannot get events!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventList events = new EventList();
|
||||||
|
for (MatchResult match : Regex.allMatches("<span id=\"link_to_details_[^~]*?</span>", body)) {
|
||||||
|
String entry = match.group(0);
|
||||||
|
String date;
|
||||||
|
String title = "";
|
||||||
|
try {
|
||||||
|
date = Regex.regex("[A-Z][a-z], [0-9]{2}\\.[0-9]{2}\\.[0-9]{4} [0-9]{2}:[0-9]{2} - [0-9]{2}:[0-9]{2}", entry, 0);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
errorCallback.onError(new NetworkError(101412, 400, "Cannot get events!"));
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
title = Regex.regex("<div class=\"course_title\">([^<]*?)</div>", entry, 0);
|
||||||
|
} catch (NoSuchFieldException ignored) {}
|
||||||
|
if (TextUtils.isEmpty(title))
|
||||||
|
title = module.title;
|
||||||
|
ArrayList<String> docents = new ArrayList<>();
|
||||||
|
ArrayList<String> locations = new ArrayList<>();
|
||||||
|
for (MatchResult match1 : Regex.allMatches("<div class=\"appointment_details_column\">[^~]*?</div>", entry)) {
|
||||||
|
if (match1.group(0).contains("Dozenten:")) {
|
||||||
|
for (MatchResult match2 : Regex.allMatches(">([^>]*?)<small class=\"phone_portal\">", match1.group(0))) {
|
||||||
|
docents.add(match2.group(0).trim());
|
||||||
|
}
|
||||||
|
} else if (match1.group(0).contains("Räume:")) {
|
||||||
|
for (MatchResult match2 : Regex.allMatches("</b>([^~]*?)</p>", match1.group(0))) {
|
||||||
|
locations.add(match2.group(1).trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long start = UtilsDate.stringToMillis(date.substring(4, 20), "dd.MM.yyyy HH:mm");
|
||||||
|
long duration = (Integer.parseInt(date.substring(23, 25))-Integer.parseInt(date.substring(15, 17)))*60
|
||||||
|
+ Integer.parseInt(date.substring(26, 28))-Integer.parseInt(date.substring(18, 20));
|
||||||
|
duration = duration*60*1000-1;
|
||||||
|
String locationString = TextUtils.join(", ", locations);
|
||||||
|
events.add(new Event("", "Class section - Lecture", title, duration, start, ID, locationString));
|
||||||
|
}
|
||||||
|
callback.onResponse(events);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101415, error.networkResponse.statusCode, "Cannot get events!")));
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101413, error.networkResponse.statusCode, "Cannot get events!")));
|
||||||
|
}, errorCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,8 +273,10 @@ public class ModulesList extends HTTPService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HashSet<String> lvNumberSet = new HashSet<>();
|
||||||
|
lvNumberSet.add(lvNumber);
|
||||||
if (!found)
|
if (!found)
|
||||||
modulesKVV.addModule(new Semester(semType.equals("W") ? Semester.SEM_WS : Semester.SEM_SS, Integer.valueOf(semYear)), new HashSet<>(), name, new LinkedHashSet<>(), type, "", courseId, Modules.TYPE_BB);
|
modulesKVV.addModule(new Semester(semType.equals("W") ? Semester.SEM_WS : Semester.SEM_SS, Integer.valueOf(semYear)), lvNumberSet, name, new LinkedHashSet<>(), type, "", courseId, Modules.TYPE_BB);
|
||||||
latch[0]--;
|
latch[0]--;
|
||||||
if (latch[0] == 0)
|
if (latch[0] == 0)
|
||||||
callback.onResponse(modulesKVV);
|
callback.onResponse(modulesKVV);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class HTTPService {
|
|||||||
get(url, cookies, response, error, false);
|
get(url, cookies, response, error, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void get(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error, boolean noBody) {
|
private void get(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error, boolean noBody) {
|
||||||
int requestMethod = noBody ? Request.Method.HEAD : Request.Method.GET;
|
int requestMethod = noBody ? Request.Method.HEAD : Request.Method.GET;
|
||||||
HttpRequest request = new HttpRequest(requestMethod, url, response, error) {
|
HttpRequest request = new HttpRequest(requestMethod, url, response, error) {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user