-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset.py
58 lines (35 loc) · 1.3 KB
/
reset.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
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
from sys import executable
from subprocess import check_call
import sqlite3
def clear_all():
print("Cleaning database .")
# Connects to the database
history = sqlite3.connect(r"assets\history\history.db")
# Sets cursor
cursor = history.cursor()
try:
# Gets ready to save it to database
cursor.execute("DELETE FROM history")
# Saves it to database
history.commit()
except sqlite3.OperationalError:
# if table not found create table
cursor.execute("CREATE TABLE history (\n\tactions_id INTEGER NOT NULL,\n\tJSON TEXT NOT NULL,\n\tPRIMARY KEY (actions_id)\n)")
# Saves table
history.commit()
# Terminates connection
history.close()
print("Database cleared.")
# To delete all __pycache__
check_call([executable, "-m", "pyclean", "."])
print("Clearing Json .")
# to clear Json history
with open(r"assets\history\history.json", "w") as json:
json.write("[]")
print("Json history cleared.")
# to clear images history
with open(r"assets\images\images.png", "w"):
pass
print("Image file cleared.")
if __name__ == "__main__":
clear_all()