PYTHON 10
Attendance Script - vnoone edits Guest on 27th January 2025 07:01:30 PM
  1. import csv
  2. from datetime import datetime
  3. import tkinter as tk
  4. from tkinter import filedialog
  5. import os
  6.  
  7. '''
  8. Original File by David Katz...
  9.  
  10. This is my script for CSIT 111 to take attendance.
  11.  
  12. The File Open dialog at the beginning can be used to select a CSV file
  13. exported from Brightspace's Grades page for the given course.
  14.  
  15. After a loop of all students in the roster, we repeat once to make sure we
  16. got everyone, and then finally save the list of absent students in a dated file.
  17.  
  18. Edits by Veronica Noone 1/27/2025
  19.  
  20. added Try/Except to prevent error when canceling file open.
  21. Added filename to make code more dynamic for use with multiple CSVs
  22. Modulairzed for readability
  23. took our references to CSIT 111 and made messaging more generic for use with other classes.
  24. Added list of potential responses to increase readability
  25. Edited display text slighty "they" to "you" etc.
  26.  
  27. '''
  28.  
  29. # Create a barebones GUI window necessary for the file dialog
  30. root = tk.Tk()
  31. root.withdraw()  # Hide the window
  32.  
  33. print("Export a CSV file from Brightspace Course --> Grades --> Export --> Export to CSV")
  34. print("Ensure both First Name and Last Name are checked")
  35.  
  36. # Show a file open dialog to get file for later
  37. file_path = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")], title="Open CSV export from Brightspace's Grades page")
  38. # Lists of students
  39. potentially_absent = []
  40. marked_absent = []
  41. posResponses = ["yes","y","yea","p","here"]
  42.  
  43.  
  44. def takeAttendance():
  45.     # Loop through the rows in the CSV file
  46.     try:
  47.         with open(file_path, mode='r') as file:
  48.             # Create a CSV DictReader object to parse the file
  49.             # Read the CSV file exported from Brightspace's Grades page
  50.             csv_reader = csv.DictReader(file)
  51.             print("Attendance from " + os.path.basename(file.name) + "\n")
  52.             for student in csv_reader:
  53.                     # Print each name using dictionary lookups
  54.                     print(student.get('First Name') + " " + student.get('Last Name'))
  55.            
  56.                     # Wait for user input on student presence
  57.                     presence = input("\nAre you here?\n")
  58.                     if presence in posResponses:
  59.                             print("Welcome to CSIT 111, " + student.get('First Name') + "!\n")
  60.                     else:
  61.                             potentially_absent.append(student.get('First Name') + ' ' + student.get('Last Name'))
  62.                             print("Added " + student.get('First Name') + " to the potentially absent list for later.\n")
  63.             print("That's the whole course roster. Now repeating potentially absent students.\n")
  64.     except FileNotFoundError:
  65.         print("FileNotFoundError: File not found.")
  66.         quit()
  67. #end takeAttendance
  68.        
  69.  
  70. def secChance():
  71.     # Loop through the list of potentially absent students
  72.     for name in potentially_absent:
  73.             print(name)
  74.             presence = input("\nAre they here?\n")
  75.             if presence in posResponses:
  76.                     print("Welcome to class, " + name + "!\n")
  77.             else:
  78.                     marked_absent.append(name)
  79.                     print("Marked " + name + " as absent.\n")
  80.                    
  81.     # Generate a filename for today's absentees
  82.     absent_file = "absent-" + datetime.today().strftime('%m-%d-%Y' + ".txt")
  83.      
  84.     # Open the absent file for writing/appending
  85.     with open(absent_file, 'a') as file:
  86.             # Append the final absentee list
  87.             print("Absentee list:")
  88.             file.write("Absentee list: \n")
  89.             for name in marked_absent:
  90.                     print(name)
  91.                     file.write(name + "\n")
  92. #end secChance
  93.  
  94. takeAttendance()
  95. secChance()

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.