second init

This commit is contained in:
2024-11-27 02:58:28 +03:00
commit 10aa70702c
19 changed files with 875 additions and 0 deletions

36
app/db.py Normal file
View File

@@ -0,0 +1,36 @@
# Импорт модулей стандартной библиотеки
import sqlite3
import json
class DataBase(object):
"""..."""
def __init__(self, path):
super(DataBase, self).__init__()
self.path = path
def connect(self) -> bool:
self.conn = sqlite3.connect(self.path)
return True
def close(self) -> bool:
self.conn.close()
return True
def commit(self) -> None:
self.conn.commit()
return True
def add_data(self, data, wins: bool) -> bool: # wins изменит на Enum
if wins:
table = 'wins'
else:
table = 'donates'
cur = self.conn.cursor()
cur.execute('INSERT INTO {table} (\'data\') VALUES (\'{data}\')'.format(table=table, data=json.dumps(data)))
self.commit()
cur.close()
return True