From ce4d0b03051ce7e992aa9bf7499bf92384a36391 Mon Sep 17 00:00:00 2001 From: Isaiah Andrade Date: Wed, 29 Jan 2025 23:02:23 -0500 Subject: [PATCH] Add oopsie check for student This commit adds an 'oopsie' command to the parser with a required '-u/--username' argument. It also adds an 'oopsie' function to check if a specific student has used an oopsie. If they have, the assignment name and timestamp is displayed; otherwise it displays the student has not used their oopsie. Signed-off-by: Isaiah Andrade --- mailman/inspector.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mailman/inspector.py b/mailman/inspector.py index 70007395..2efe3310 100755 --- a/mailman/inspector.py +++ b/mailman/inspector.py @@ -26,6 +26,11 @@ def main(): help='Select the assignment', required=True) + oopsie_parser = command_parsers.add_parser('oopsie') + oopsie_parser.add_argument('-u', '--username', + help='Check if a student used an Oopsie', + required=True) + # Dictionary containing the desired command and all flags with their values kwargs = vars(parser.parse_args()) # Subparsers store their name in the destination `'command'` @@ -55,6 +60,15 @@ def missing(assignment): if user.username not in submitted: print(user.username) +def oopsie(username): + try: + query = db.Oopsie.get(db.Oopsie.user == username) + time = datetime.fromtimestamp(query.timestamp).astimezone().isoformat() + print(f'{username} has used an oopsie on assignment: ' + f'{query.assignment} at {time}.') + except peewee.DoesNotExist: + print(f'{username} has not used an oopsie.') + if __name__ == '__main__': main()