-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
73 lines (65 loc) · 1.67 KB
/
Copy pathdb.py
File metadata and controls
73 lines (65 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sqlite3
from datetime import datetime, UTC
DB_NAME = "team_activity.db"
def get_connection():
conn = sqlite3.connect(DB_NAME)
conn.row_factory = sqlite3.Row
return conn
def init_db():
conn = get_connection()
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS activities (
id INTEGER PRIMARY KEY AUTOINCREMENT,
employee_name TEXT NOT NULL,
activity_date TEXT NOT NULL,
category TEXT NOT NULL,
task_type TEXT NOT NULL,
task_name TEXT NOT NULL,
duration_hour TEXT NOT NULL,
notes TEXT,
created_at TEXT NOT NULL
)
""")
conn.commit()
conn.close()
def add_activity(employee_name,
activity_date,
category,
task_type,
task_name,
duration_hour,
notes):
conn = get_connection()
cursor = conn.cursor()
cursor.execute("""
INSERT INTO activities (
employee_name,
activity_date,
category,
task_type,
task_name,
duration_hour,
notes,
created_at
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""", (employee_name,
activity_date,
category,
task_type,
task_name,
duration_hour,
notes,
datetime.now(UTC).isoformat())
)
conn.commit()
conn.close()
def get_all_activities():
conn = get_connection()
rows = conn.execute("""
SELECT * FROM activities
ORDER BY activity_date DESC, id DESC
""").fetchall()
conn.close()
return rows