omarkashif commited on
Commit
04c22f4
·
verified ·
1 Parent(s): ab17c9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
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.lower()] = row[0:] # Store all 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].strip() 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,17 +59,11 @@ class AttendanceTracker:
59
  if new_column_name not in updated_header:
60
  updated_header.append(new_column_name)
61
 
62
- for name_lower, statuses in existing_data.items():
63
  # Append new status for the new column
64
- name = statuses[0] # Retrieve the original name
65
- status = "Present" if name_lower in [n.lower() for n in new_attendance_list] else "Absent"
66
  statuses.append(status)
67
- updated_rows.append(statuses)
68
-
69
- # Add entries for any new names not in existing data
70
- for name in new_attendance_list:
71
- if name.lower() not in existing_data:
72
- updated_rows.append([name] + ["Absent"] * (len(updated_header) - 1))
73
 
74
  # Save the updated attendance list locally
75
  with open(local_file_path, "w", newline="") as f:
@@ -103,4 +97,4 @@ iface = gr.Interface(
103
  description="Upload a CSV file of today's attendance to update the attendance file for the selected course."
104
  )
105
 
106
- iface.launch()
 
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
  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 in new_attendance_list 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:
 
97
  description="Upload a CSV file of today's attendance to update the attendance file for the selected course."
98
  )
99
 
100
+ iface.launch()