-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
115 lines (79 loc) · 2.63 KB
/
database.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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 values('question', 'answert')
query = "INSERT INTO questionsAndAnswers values('"+question+"', '"+answer+"')"
cur.execute(query)
con.commit()
def get_answer_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 values('question', 'answert')
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 values('question', 'answert')
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 values('question', 'answert')
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()
query = "select value from memory where name = 'last_seen_date'"
cur.execute(query)
return str(cur.fetchall()[0][0])
def turn_on_speech():
if (check_internet_connection):
con = create_connection()
cur = con.cursor()
query = "update memory set value = 'on' where name = 'speech'"
cur.execute(query)
con.commit()
return ("Ok i will speak now")
else:
return ("Hey please turn on internet first. ")
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