From 623f87ad4859562aa0625a1ed5722dc30db0bed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Thu, 17 Jan 2019 18:02:12 +0100 Subject: [PATCH] Functionalize comparison and clearance message bit --- ib-clearance.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ib-clearance.py b/ib-clearance.py index 4ceef8f..d6c77b8 100755 --- a/ib-clearance.py +++ b/ib-clearance.py @@ -147,12 +147,30 @@ def parse_time_string(timestring): return structtime +def clear(finish_time): + """Return clearance message. + + Compare the current time with finishing time and return relevant + clearance message. + + :param finish_time: finishing time, struct_time object + """ + current_time = parse_time_string(time.strftime("%H:%M")) + if finish_time == None: + message = "Student has no lessons today, clear to leave." + elif finish_time < current_time: + message = "Student has finished for today, clear to leave." + else: + message = "Student still has lessons, clearance not granted." + return message + + def exit_sequence(): """Initiate exit sequence. Asks user to enter character, and exits program if X is pressed. """ - print("\nPress X to exit.") + print("Press X to exit.") key = getch() if isinstance(key, bytes): # msvcrt.getch returns type bytes, decode into str. @@ -171,14 +189,8 @@ def main(): student_data = get_data(conn) day = time.strftime("%A").lower() finish_time = select_final_time(conn, day, student_data) - current_time = parse_time_string(time.strftime("%H:%M")) - if finish_time == None: - print("\nStudent has no lessons today, clear to leave.") - elif finish_time < current_time: - print("\nStudent has finished for today, clear to leave.") - else: - print("\nStudent still has lessons, clearance not granted.") + print("\n" + clear(finish_time) + "\n") exit_sequence()