Jayabalambika commited on
Commit
7d02576
·
verified ·
1 Parent(s): f81a39c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -6,31 +6,39 @@ from datetime import datetime
6
  # Database Setup
7
  db_file = "attendance_records.db"
8
 
9
- conn = sqlite3.connect(db_file)
10
- cursor = conn.cursor()
11
-
12
- # Create attendance table if not exists
13
- cursor.execute("""
14
- CREATE TABLE IF NOT EXISTS attendance (
15
- id INTEGER PRIMARY KEY AUTOINCREMENT,
16
- name TEXT,
17
- day TEXT,
18
- date TEXT,
19
- status TEXT
20
- )
21
- """)
22
- conn.commit()
23
-
24
  # Helper Functions
 
 
 
 
 
25
  def log_attendance(name, day, date, status):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  cursor.execute("""
27
  INSERT INTO attendance (name, day, date, status)
28
  VALUES (?, ?, ?, ?)
29
  """, (name, day, date, status))
30
  conn.commit()
 
31
  return "Attendance logged successfully!"
32
 
33
  def calculate_fees():
 
 
 
34
  # Calculate attendance fees
35
  cursor.execute("""
36
  SELECT name, COUNT(*) * (1000 / 12) AS fees
@@ -40,6 +48,7 @@ def calculate_fees():
40
  """)
41
  fees_data = cursor.fetchall()
42
  fees_dict = {row[0]: row[1] for row in fees_data}
 
43
  return fees_dict
44
 
45
  def create_end_of_month_table():
@@ -47,6 +56,9 @@ def create_end_of_month_table():
47
  if today.day != pd.Period(today.strftime("%Y-%m")).days_in_month:
48
  return "It's not the end of the month yet."
49
 
 
 
 
50
  # Create end-of-month table
51
  month = today.strftime("%Y-%m")
52
  table_name = f"fees_{month.replace('-', '_')}"
@@ -78,6 +90,7 @@ def create_end_of_month_table():
78
  """, (name, email, fees))
79
 
80
  conn.commit()
 
81
  return f"End-of-month table '{table_name}' created successfully!"
82
 
83
  def submit_attendance(name, day, date, status):
 
6
  # Database Setup
7
  db_file = "attendance_records.db"
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # Helper Functions
10
+ def get_db_connection():
11
+ """Create a new database connection."""
12
+ conn = sqlite3.connect(db_file)
13
+ return conn
14
+
15
  def log_attendance(name, day, date, status):
16
+ conn = get_db_connection()
17
+ cursor = conn.cursor()
18
+
19
+ cursor.execute("""
20
+ CREATE TABLE IF NOT EXISTS attendance (
21
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
22
+ name TEXT,
23
+ day TEXT,
24
+ date TEXT,
25
+ status TEXT
26
+ )
27
+ """)
28
+ conn.commit()
29
+
30
  cursor.execute("""
31
  INSERT INTO attendance (name, day, date, status)
32
  VALUES (?, ?, ?, ?)
33
  """, (name, day, date, status))
34
  conn.commit()
35
+ conn.close()
36
  return "Attendance logged successfully!"
37
 
38
  def calculate_fees():
39
+ conn = get_db_connection()
40
+ cursor = conn.cursor()
41
+
42
  # Calculate attendance fees
43
  cursor.execute("""
44
  SELECT name, COUNT(*) * (1000 / 12) AS fees
 
48
  """)
49
  fees_data = cursor.fetchall()
50
  fees_dict = {row[0]: row[1] for row in fees_data}
51
+ conn.close()
52
  return fees_dict
53
 
54
  def create_end_of_month_table():
 
56
  if today.day != pd.Period(today.strftime("%Y-%m")).days_in_month:
57
  return "It's not the end of the month yet."
58
 
59
+ conn = get_db_connection()
60
+ cursor = conn.cursor()
61
+
62
  # Create end-of-month table
63
  month = today.strftime("%Y-%m")
64
  table_name = f"fees_{month.replace('-', '_')}"
 
90
  """, (name, email, fees))
91
 
92
  conn.commit()
93
+ conn.close()
94
  return f"End-of-month table '{table_name}' created successfully!"
95
 
96
  def submit_attendance(name, day, date, status):