-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
30 lines (25 loc) · 926 Bytes
/
Copy pathdatabase.py
File metadata and controls
30 lines (25 loc) · 926 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
import sqlite3
class DatabaseManager:
def __init__(self, db_name='system_monitor.db'):
self.conn = sqlite3.connect(db_name)
self.cursor = self.conn.cursor()
self.create_table()
def create_table(self):
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS system_stats (
cpu REAL,
total_ram REAL,
used_ram REAL,
total_rom REAL,
used_rom REAL
)
''')
self.conn.commit()
def insert_data(self, cpu: float, total_ram: float, used_ram: float, total_rom: float, used_rom: float):
self.cursor.execute('''
INSERT INTO system_stats (cpu, total_ram, used_ram, total_rom, used_rom)
VALUES (?, ?, ?, ?, ?)
''', (cpu, total_ram, used_ram, total_rom, used_rom))
self.conn.commit()
def close(self):
self.conn.close()