-
Notifications
You must be signed in to change notification settings - Fork 103
/
db.py
41 lines (30 loc) · 953 Bytes
/
db.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cPickle
import sqlite3
from uuid import uuid4
__database__ = "database.sqlite3"
def setup():
conn = getConnection()
c = conn.cursor()
c.execute("""
create table if not exists assistants(assistantId text primary key, assistant assi)
""")
conn.commit()
c.close()
conn.close()
def getConnection():
return sqlite3.connect(__database__, detect_types=sqlite3.PARSE_DECLTYPES)
class Assistant(object):
def __init__(self, assistantId=str.upper(str(uuid4()))):
self.assistantId = assistantId
self.censorspeech = None
self.timeZoneId = None
self.language = None
self.region = None
def adaptAssistant(assistant):
return cPickle.dumps(assistant)
def convertAssistant(fromDB):
return cPickle.loads(fromDB)
sqlite3.register_adapter(Assistant, adaptAssistant)
sqlite3.register_converter("assi", convertAssistant)