-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.py
52 lines (46 loc) · 1.48 KB
/
options.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
#!/usr/bin/env python
import sqlite3
from db import conn, c
from audio_to_text import DEFAULT_DEST, DEFAULT_SRC
def set_defaults(options_dict):
if 'dest' not in options_dict:
options_dict['dest'] = DEFAULT_DEST
if 'src' not in options_dict:
options_dict['src'] = DEFAULT_SRC
return options_dict
# options_str looks like "#options dest:en src:fr"
def parse_options(options_str):
tokens = options_str.split()[1:]
options_dict = {}
for token in tokens:
try:
[key, val] = token.split(':')
options_dict[key] = val
except:
pass
return set_defaults(options_dict)
def update_options(sender_id, options):
options = set_defaults(options)
print('Inside update_options, options: ')
print(options)
q = 'INSERT OR IGNORE INTO users (id, src, dest) VALUES (?, ?, ?)'
conn.execute(q, (str(sender_id), options['src'], options['dest']))
q = 'UPDATE users SET src=?, dest=? where id = ?'
conn.execute(q, (options['src'], options['dest'], str(sender_id)))
print('Updated users options. Src: %s, Dest: %s' % (options['src'], options['dest']))
c.commit()
def get_options(sender_id):
print('AAAAAAAAAAAAAAAAAAA')
q = 'SELECT src, dest from users where id=%s' % (str(sender_id))
print(q)
conn.execute(q)
(src, dest) = conn.fetchone()
return {
'src': src,
'dest': dest
}
# return (src, dest)
default_opts = {
'src': 'auto',
'dest': 'en'
}