-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
40 lines (31 loc) · 1.58 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
from pathlib import Path
from pysondb import db
db_directory = Path('db')
db_directory.mkdir(exist_ok=True)
user_pronunciation_db = db.getDb("db/tbl_user_pronunciation.json")
user_pronunciation_audio_settings_db = db.getDb("db/tbl_user_pronunciation_audio_settings.json")
def get_user_pronunciation(user_id: str):
pronunciation = user_pronunciation_db.getByQuery({'userId': user_id})
if not pronunciation:
return dict()
else:
return pronunciation[0]
def save_user_pronunciation(user_id: str, legal_first_name: str, legal_last_name: str, preferred_name: str,
audio_file_name: str):
saved_pronunciation = get_user_pronunciation(user_id)
if not saved_pronunciation:
user_pronunciation_db.add(
{'userId': user_id, 'legalFirstName': legal_first_name, 'legalLastName': legal_last_name,
'preferredName': preferred_name, 'audioFileName': audio_file_name})
saved_pronunciation = dict()
else:
user_pronunciation_db.updateById(saved_pronunciation['id'],
{'userId': user_id, 'legalFirstName': legal_first_name,
'legalLastName': legal_last_name,
'preferredName': preferred_name, 'audioFileName': audio_file_name})
return saved_pronunciation
def remove_user_pronunciation(user_id: str):
saved_pronunciation = get_user_pronunciation(user_id)
if saved_pronunciation:
user_pronunciation_db.deleteById(saved_pronunciation['id'])
return saved_pronunciation