-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.py
39 lines (27 loc) · 1.07 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
#!/usr/bin/python
import sqlite3
database_file = "database.db"
def get_response(dictionary):
intent = dictionary['intent']
subject = dictionary['subject']
connection = sqlite3.connect(database_file)
cursor = connection.cursor()
cursor.execute("SELECT %s FROM subjects WHERE subject='%s'" %(intent, subject))
response = cursor.fetchone()
if response:
return response[0]
else:
return "দুঃখিত, এব্যাপারে আমার কাছে কোনো তথ্য নেই।"
def record_exists(subject):
connection = sqlite3.connect(database_file)
cursor = connection.cursor()
cursor.execute("SELECT EXISTS(SELECT 1 FROM subjects WHERE subject='%s')" %(subject))
response = cursor.fetchone()[0]
return True if response == 1 else False
def get_subjects():
connection = sqlite3.connect(database_file)
cursor = connection.cursor()
cursor.execute("SELECT subject FROM subjects")
response = cursor.fetchall()
subjects = [element[0] for element in response]
return subjects