forked from janrueth/SiriServerCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
44 lines (35 loc) · 1.19 KB
/
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
42
43
44
#!/usr/bin/python
# -*- coding: utf-8 -*-
from siriObjects.systemObjects import SetAssistantData
from uuid import uuid4
import cPickle
import logging
import sqlite3
__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():
try:
return sqlite3.connect(__database__, detect_types=sqlite3.PARSE_DECLTYPES, timeout=10.0, check_same_thread=False)
except sqlite3.Error.OperationalError as e:
logging.getLogger().error("Connecting to the internal database timed out, there are probably to many connections accessing the database")
logging.getLogger().error(e)
return None
class Assistant(SetAssistantData):
def __init__(self):
self.assistantId = None
self.nickName = u''
self.firstName=u''
def adaptAssistant(assistant):
return cPickle.dumps(assistant)
def convertAssistant(fromDB):
return cPickle.loads(fromDB)
sqlite3.register_adapter(Assistant, adaptAssistant)
sqlite3.register_converter("assi", convertAssistant)