From 8b380201461273cc2345a531e89d11682c2977c8 Mon Sep 17 00:00:00 2001
From: Imran Hussain <imranh@sucs.org>
Date: Sun, 10 Mar 2019 18:21:24 +0000
Subject: [PATCH] Handle when there are no users that are expired

---
 sucsam.py | 63 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 25 deletions(-)

diff --git a/sucsam.py b/sucsam.py
index 9cce39a..8f01f0e 100644
--- a/sucsam.py
+++ b/sucsam.py
@@ -382,11 +382,15 @@ def reminderMenu():
 			print(str(ass[0]) + " because the DB says: " + str(ass[1]))
 		reminderMenu()
 	if option == "2":
-		sendReminderEmail(studentsBad)
-		sendReminderEmail(societiesBad)
-		sendReminderEmail(associatesBad)
+		if len(studentsBad) > 0:
+			sendReminderEmail(studentsBad)
+		if len(societiesBad) > 0:
+			sendReminderEmail(societiesBad)
+		if len(associatesBad) > 0:
+			sendReminderEmail(associatesBad)
 	if option == "2.1":
-		sendReminderEmail(studentsBad)
+		if len(studentsBad) > 0:
+			sendReminderEmail(studentsBad)
 	if option == "0":
 		mainMenu()
 	else:
@@ -425,34 +429,43 @@ def deleteMenu(deleteArray):
 				print("\x1b[1;31mInvalid user.\x1b[0m")
 		deleteMenu(deleteArray)
 	elif option == "3":
-		for student in studentsBad:
-			print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1]))
-			deleteArray.append(student[0])
-		for soc in societiesBad:
-			print("Adding " + str(soc[0]) + " to the list because the DB says: " + str(soc[1]))
-			deleteArray.append(soc[0])
-		for ass in associatesBad:
-			print("Adding " + str(ass[0]) + " to the list because the DB says: " + str(ass[1]))
-			deleteArray.append(ass[0])
-		deleteMenu(deleteArray)
-	elif option == "3.1":
-		for student in studentsBad:
-			print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1]))
-			deleteArray.append(student[0])
-	elif option == "3.5":
-		for student in studentsBad:
-			if student[1] == "delete":
+		if len(studentsBad) > 0:
+			for student in studentsBad:
 				print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1]))
 				deleteArray.append(student[0])
-		for soc in societiesBad:
-			if soc[1] == "delete":
+		if len(societiesBad) > 0:
+			for soc in societiesBad:
 				print("Adding " + str(soc[0]) + " to the list because the DB says: " + str(soc[1]))
 				deleteArray.append(soc[0])
-		for ass in associatesBad:
-			if ass[1] == "delete":
+		if len(societiesBad) > 0:
+			for ass in associatesBad:
 				print("Adding " + str(ass[0]) + " to the list because the DB says: " + str(ass[1]))
 				deleteArray.append(ass[0])
 		deleteMenu(deleteArray)
+	elif option == "3.1":
+		if len(studentsBad) > 0:
+			for student in studentsBad:
+				print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1]))
+				deleteArray.append(student[0])
+		print("No students look like the need deleting.")
+		deleteMenu(deleteArray)
+	elif option == "3.5":
+		if len(studentsBad) > 0:
+			for student in studentsBad:
+				if student[1] == "delete":
+					print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1]))
+					deleteArray.append(student[0])
+		if len(societiesBad) > 0:
+			for soc in societiesBad:
+				if soc[1] == "delete":
+					print("Adding " + str(soc[0]) + " to the list because the DB says: " + str(soc[1]))
+					deleteArray.append(soc[0])
+		if len(associatesBad) > 0:
+			for ass in associatesBad:
+				if ass[1] == "delete":
+					print("Adding " + str(ass[0]) + " to the list because the DB says: " + str(ass[1]))
+					deleteArray.append(ass[0])
+		deleteMenu(deleteArray)
 	elif option == "9":
 		if debugmode > 0:
 			print("Debugmode is set. Doing No Deletes.")
-- 
GitLab