-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.py
More file actions
99 lines (77 loc) · 2.61 KB
/
database.py
File metadata and controls
99 lines (77 loc) · 2.61 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
95
96
97
98
99
import sqlite3
from internet import check_internet_connection
def create_connection():
connection = sqlite3.connect("memory.db")
return connection
def get_questions_and_answers():
con = create_connection()
cur = con.cursor()
cur.execute('select * from questionsAndAnswers')
return cur.fetchall()
def insert_question_and_answer(question,answer):
con=create_connection()
cur=con.cursor()
#insert into tablename value ('question','answers')
query="INSERT INTO questionsAndAnswers values('"+question+"','"+answer+"')"
cur.execute(query)
con.commit()
def get_answers_from_memory(question):
rows = get_questions_and_answers()
answer = ""
for row in rows:
if (row[0].lower()) in (question.lower()):
answer = row[1]
break
return answer
def get_name():
con=create_connection()
cur=con.cursor()
#insert into tablename value ('question','answers')
query="select value from memory where name = 'assistant name'"
cur.execute(query)
return cur.fetchall()[0][0]
def update_name(new_name):
con=create_connection()
cur=con.cursor()
#insert into tablename value ('question','answers')
query="update memory set value = '"+new_name+"' where name = 'assistant name'"
cur.execute(query)
con.commit()
def update_last_seen(last_seen_date):
con=create_connection()
cur=con.cursor()
#insert into tablename value ('question','answers')
query="update memory set value = '"+str(last_seen_date)+"' where name = 'last seen date'"
cur.execute(query)
con.commit()
def get_last_seen():
con=create_connection()
cur=con.cursor()
#insert into tablename value ('question','answers')
query="select value from memory where name = 'last seen date'"
cur.execute(query)
return str(cur.fetchall()[0][0])
def turn_on_speech():
con=create_connection()
cur=con.cursor()
query="update memory set value = 'on' where name = 'speech'"
cur.execute(query)
con.commit()
return ("speech turned on")
def turn_off_speech():
con=create_connection()
cur=con.cursor()
query="update memory set value = 'off' where name = 'speech'"
cur.execute(query)
con.commit()
return ("ok i won't speak")
def speak_is_on():
con=create_connection()
cur=con.cursor()
query="select value from memory where name = 'speech'"
cur.execute(query)
ans=str(cur.fetchall()[0][0])
if ans == "on":
return True
else:
return False