-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabank.py
More file actions
94 lines (74 loc) · 3.26 KB
/
Databank.py
File metadata and controls
94 lines (74 loc) · 3.26 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# sql
import sqlite3
# config
from configparser import ConfigParser
# general base modules
from dataclasses import dataclass
@dataclass
class Databank:
__dbConn: sqlite3.Connection
def __init__(self):
self.__dbConn = sqlite3.connect("assets/databanks/database.db")
def getDbConn(self):
return self.__dbConn
def getCommandUsage(self, name: str):
dbCursor = self.__dbConn.cursor()
dbCursor.execute(f"SELECT usage FROM commands WHERE name = '{name}'")
return dbCursor.fetchall()[0][0]
def useCommand(self, name: str):
dbCursor = self.__dbConn.cursor()
dbCursor.execute(f"UPDATE commands SET usage = usage + 1 WHERE name = '{name}'")
def addCommand(self, name: str, keywords: str, output: str):
dbCursor = self.__dbConn.cursor()
dbCursor.execute("SELECT name FROM commands")
if name not in str(dbCursor.fetchall()):
dbCursor.execute("INSERT INTO commands (name, keywords, output, usage) VALUES (?, ?, ?, 0)",
(name, keywords, output))
else:
print("command is already in database")
def delCommmand(self, name: str):
dbCursor = self.__dbConn.cursor()
dbCursor.execute(f"DELETE FROM commands WHERE name = '{name}'")
def updateCommand(self, name: str, newName: str, keywords="", output=""):
dbCursor = self.__dbConn.cursor()
if newName != "":
dbCursor.execute(f"UPDATE commands SET name = '{newName}' WHERE name = '{name}'")
if keywords != "":
dbCursor.execute(f"UPDATE commands SET keywords = '{keywords}' WHERE name = '{name}'")
if output != "":
dbCursor.execute(f"UPDATE commands SET output = '{output}' WHERE name = '{name}'")
def getTable(self, name: str):
dbCursor = self.getDbConn().cursor()
dbCursor.execute(f"SELECT * FROM {name}")
return dbCursor.fetchall()
def addTask(self, name: str, date: str):
dbCursor = self.__dbConn.cursor()
dbCursor.execute("INSERT INTO tasks (name, date, done) VALUES (?, ?, ?)", (name, date, 0))
def delTask(self, name):
dbCursor = self.__dbConn.cursor()
dbCursor.execute(f"DELETE FROM tasks WHERE name = '{name}'")
def taskDone(self, name):
dbCursor = self.__dbConn.cursor()
dbCursor.execute(f"UPDATE tasks SET done = 1 WHERE name = '{name}'")
def defaultConfig(self):
config_object = ConfigParser()
config_object["CONFIG"] = {
"music player": "AIMP",
"music folder": "F:\Data\Music",
"default location": "Mainz",
"weather api key": "b2a39070b9ee41e29258d45e327d6e4b"
}
with open("assets/config.ini", "w") as conf:
config_object.write(conf)
def getConfig(self, attribute: str):
config_object = ConfigParser()
config_object.read("assets/config.ini")
config = config_object["CONFIG"]
return config[attribute]
def updateConfig(self, attribute: str, value: str):
config_object = ConfigParser()
config_object.read("config.ini")
config = config_object["CONFIG"]
config[attribute] = value
with open("assets/config.ini", "w") as conf:
config_object.write(conf)