-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.py
33 lines (26 loc) · 1.05 KB
/
Database.py
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
import sqlite3, logging
logger = logging.getLogger(__name__)
class Database:
def __init__(self):
self.db_name = "DoNotWhisper.db"
self.execute("""
CREATE TABLE IF NOT EXISTS WhisperIgnore (
username TEXT,
PRIMARY KEY (username)
);""")
def execute(self, sql, values=None, fetch=False):
with sqlite3.connect(self.db_name) as conn:
cur = conn.cursor()
if values is None:
cur.execute(sql)
else:
cur.execute(sql, values)
conn.commit()
if fetch:
return cur.fetchall()
def add_whisper_ignore(self, username):
self.execute("INSERT OR IGNORE INTO WhisperIgnore(username) SELECT ?", (username,))
def check_whisper_ignore(self, username):
return self.execute("SELECT username FROM WhisperIgnore WHERE username = ?;", (username,), fetch=True)
def remove_whisper_ignore(self, username):
self.execute("DELETE FROM WhisperIgnore WHERE username = ?", (username,))