omarkashif commited on
Commit
4c35bcb
·
verified ·
1 Parent(s): 650755d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -41,13 +41,13 @@ class AttendanceTracker:
41
  for row in reader:
42
  if row:
43
  name = row[0] # Preserve original case
44
- existing_data[name] = row[1:] # Store all existing columns for this name
45
 
46
  # Read the new attendance file
47
  new_attendance_list = []
48
  with open(attendance_file.name, "r") as f:
49
  reader = csv.reader(f)
50
- new_attendance_list = [row[0] for row in reader if row]
51
 
52
  # Get current date and prepare the new column name
53
  current_date = date.today().strftime("%d-%m-%Y")
@@ -59,11 +59,11 @@ class AttendanceTracker:
59
  if new_column_name not in updated_header:
60
  updated_header.append(new_column_name)
61
 
62
- for name, statuses in existing_data.items():
63
  # Append new status for the new column
64
- status = "Present" if name.lower() in new_attendance_list.lower() else "Absent"
65
- statuses.append(status)
66
- updated_rows.append([name] + statuses)
67
 
68
  # Save the updated attendance list locally
69
  with open(local_file_path, "w", newline="") as f:
 
41
  for row in reader:
42
  if row:
43
  name = row[0] # Preserve original case
44
+ existing_data[name.lower()] = row # Store the entire row with the original case
45
 
46
  # Read the new attendance file
47
  new_attendance_list = []
48
  with open(attendance_file.name, "r") as f:
49
  reader = csv.reader(f)
50
+ new_attendance_list = [row[0].strip().lower() for row in reader if row] # Convert to lower case for comparison
51
 
52
  # Get current date and prepare the new column name
53
  current_date = date.today().strftime("%d-%m-%Y")
 
59
  if new_column_name not in updated_header:
60
  updated_header.append(new_column_name)
61
 
62
+ for name_lower, row in existing_data.items():
63
  # Append new status for the new column
64
+ status = "Present" if name_lower in new_attendance_list else "Absent"
65
+ row.append(status)
66
+ updated_rows.append(row)
67
 
68
  # Save the updated attendance list locally
69
  with open(local_file_path, "w", newline="") as f: