37 lines
877 B
Python
37 lines
877 B
Python
|
# Импорт модулей стандартной библиотеки
|
||
|
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
|