From a7525c00379c22f5a138ab91f8247d162ba31a8b Mon Sep 17 00:00:00 2001
From: Magnus Giesbert <magnus@fsmpi.rwth-aachen.de>
Date: Sun, 3 May 2020 00:50:51 +0200
Subject: [PATCH] Fix Issue #382

---
 importer.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/importer.py b/importer.py
index 90e893b..6babd62 100644
--- a/importer.py
+++ b/importer.py
@@ -139,10 +139,11 @@ def fetch_ro_course_events(item):
 	args = urllib.parse.parse_qs(url.query)
 	if 'pStpSpNr' in args: # Legacy URLs
 		id = args['pStpSpNr'][0]
-	elif url.path.split('/')[-2] == 'courses': # New URLs
-		id = url.path.split('/')[-1]
-	else:
-		flash("Ungültige URL: '"+i['url']+"'")
+    elif len(url.path.split('/')) > 1 and url.path.split('/')[-2] == 'courses': # New URLs
+        id = url.path.split('/')[-1]
+    else:
+        flash("Ungültige URL: '"+url.geturl()+"'")
+        return [] #cant get events from wrong URL so just return empty list
 	cal = icalendar.Calendar().from_ical(fetch_ro_course_ical(id))
 	events = []
 	for comp in cal.subcomponents:
-- 
GitLab