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()