-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseConfig.py
More file actions
65 lines (42 loc) · 1.54 KB
/
ParseConfig.py
File metadata and controls
65 lines (42 loc) · 1.54 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Parse config file"""
from os import environ
import json
CONFIG = json.load(open('config.json'))
def get_env():
"""Return enviroment ['dev' or 'prod']"""
return environ.get('ENV')
def get_token():
"""Return token"""
return environ.get("TOKEN")
def get_url():
"""Return application url"""
return environ.get("URL")
def get_db_config():
"""Return database connection config"""
return {'dbname': environ.get('DB_NAME'), 'host': environ.get('DB_HOST'),
'port': environ.get('DB_PORT'), 'user': environ.get('DB_USER'),
'passwd': environ.get('DB_PASSWD'), 'tables':
{'users': CONFIG['tables']['users'], 'complaints': CONFIG['tables']['complaints'],
'status': CONFIG['tables']['status']}
}
def get_reg_btn(lang, btn_name):
"""Return button text for registration"""
return _get_text(lang, 'menus', 'reg_menu', btn_name)
def get_main_menu_btn(lang, btn_name):
"""Return button text for main menu"""
return _get_text(lang, 'menus', 'main_menu', btn_name)
def get_conversations(lang, *args):
""" Return dict with conversations messages according to language """
return _get_text(lang, 'conversations', *args)
def _get_text(lang, *args):
"""Return text from config.json """
lang = _format_lang(lang)
if not lang in CONFIG['lang']:
lang = 'en'
text = CONFIG['lang'][lang]
for arg in args:
text = text[arg]
return text
def _format_lang(lang):
"""Return formated lang """
return lang.split('-')[0]