Functionalize comparison and clearance message bit
This commit is contained in:
		@@ -147,12 +147,30 @@ def parse_time_string(timestring):
 | 
				
			|||||||
    return structtime
 | 
					    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():
 | 
					def exit_sequence():
 | 
				
			||||||
    """Initiate exit sequence.
 | 
					    """Initiate exit sequence.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Asks user to enter character, and exits program if X is pressed.
 | 
					    Asks user to enter character, and exits program if X is pressed.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    print("\nPress X to exit.")
 | 
					    print("Press X to exit.")
 | 
				
			||||||
    key = getch()
 | 
					    key = getch()
 | 
				
			||||||
    if isinstance(key, bytes):
 | 
					    if isinstance(key, bytes):
 | 
				
			||||||
        # msvcrt.getch returns type bytes, decode into str.
 | 
					        # msvcrt.getch returns type bytes, decode into str.
 | 
				
			||||||
@@ -171,14 +189,8 @@ def main():
 | 
				
			|||||||
        student_data = get_data(conn)
 | 
					        student_data = get_data(conn)
 | 
				
			||||||
        day = time.strftime("%A").lower()
 | 
					        day = time.strftime("%A").lower()
 | 
				
			||||||
        finish_time = select_final_time(conn, day, student_data)
 | 
					        finish_time = select_final_time(conn, day, student_data)
 | 
				
			||||||
        current_time = parse_time_string(time.strftime("%H:%M"))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if finish_time == None:
 | 
					        print("\n" + clear(finish_time) + "\n")
 | 
				
			||||||
            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.")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        exit_sequence()
 | 
					        exit_sequence()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user