AqsaBatool680 commited on
Commit
b0e7fcb
·
verified ·
1 Parent(s): 7a6048d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import pandas as pd
3
  import datetime
4
 
5
- # Initialize the attendance DataFrame in memory (for this session)
6
  if 'attendance_df' not in st.session_state:
7
  st.session_state.attendance_df = pd.DataFrame(columns=["Student ID", "Name", "Date", "Time"])
8
 
@@ -19,19 +19,25 @@ with st.sidebar.form("attendance_form"):
19
  submit_button = st.form_submit_button("Mark Attendance")
20
 
21
  # If the form is submitted, log attendance
22
- if submit_button and student_id and student_name:
23
- current_time = datetime.datetime.now().strftime("%H:%M:%S")
24
- current_date = datetime.datetime.now().strftime("%Y-%m-%d")
25
-
26
- # Log attendance to the DataFrame
27
- st.session_state.attendance_df = st.session_state.attendance_df.append({
28
- "Student ID": student_id,
29
- "Name": student_name,
30
- "Date": current_date,
31
- "Time": current_time
32
- }, ignore_index=True)
33
-
34
- st.sidebar.success(f"Attendance marked for {student_name} ({student_id}) at {current_time}")
 
 
 
 
 
 
35
 
36
  # Admin Section to view attendance records
37
  if st.sidebar.checkbox("Show Attendance Records"):
 
2
  import pandas as pd
3
  import datetime
4
 
5
+ # Initialize session state if not already initialized
6
  if 'attendance_df' not in st.session_state:
7
  st.session_state.attendance_df = pd.DataFrame(columns=["Student ID", "Name", "Date", "Time"])
8
 
 
19
  submit_button = st.form_submit_button("Mark Attendance")
20
 
21
  # If the form is submitted, log attendance
22
+ if submit_button:
23
+ if student_id and student_name:
24
+ current_time = datetime.datetime.now().strftime("%H:%M:%S")
25
+ current_date = datetime.datetime.now().strftime("%Y-%m-%d")
26
+
27
+ # Create a DataFrame for the new attendance entry
28
+ new_data = pd.DataFrame({
29
+ "Student ID": [student_id],
30
+ "Name": [student_name],
31
+ "Date": [current_date],
32
+ "Time": [current_time]
33
+ })
34
+
35
+ # Concatenate the new data to the existing attendance DataFrame
36
+ st.session_state.attendance_df = pd.concat([st.session_state.attendance_df, new_data], ignore_index=True)
37
+
38
+ st.sidebar.success(f"Attendance marked for {student_name} ({student_id}) at {current_time}")
39
+ else:
40
+ st.sidebar.warning("Please enter both Student ID and Name.")
41
 
42
  # Admin Section to view attendance records
43
  if st.sidebar.checkbox("Show Attendance Records"):