-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
31 lines (26 loc) · 733 Bytes
/
database.py
File metadata and controls
31 lines (26 loc) · 733 Bytes
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
import os
import psycopg2
from datetime import datetime
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = os.getenv('DATABASE_URL')
def get_connection():
return psycopg2.connect(DATABASE_URL)
def log_interaction(user_id, username, action):
conn = get_connection()
cursor = conn.cursor()
cursor.execute('''
INSERT INTO logs (timestamp, user_id, username, action)
VALUES (%s, %s, %s, %s)
''', (datetime.now(), user_id, username, action))
conn.commit()
cursor.close()
conn.close()
def get_logs():
conn = get_connection()
cursor = conn.cursor()
cursor.execute('SELECT * FROM logs')
logs = cursor.fetchall()
cursor.close()
conn.close()
return logs