-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
35 lines (30 loc) · 1.04 KB
/
config.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
import db
from flask import g
class Config:
# env = {'DEV', 'LIVE'}
def __init__(self, env, db_url):
conn = db.get_connection(db_url)
cur = conn.cursor()
cur.execute('SELECT type, key, value FROM config WHERE env=%s;',
(env,))
conf_array = cur.fetchall()
self.conf_dic = {}
for conf in conf_array:
if conf[0] == 'STR':
self.conf_dic[conf[1]] = conf[2]
elif conf[0] == 'INT':
self.conf_dic[conf[1]] = int(conf[2])
cur.close()
conn.close()
def get(self, key):
return self.conf_dic.get(key)
def reload(self, env):
g.cur.execute('SELECT type, key, value FROM config WHERE env=%s;',
(env,))
conf_array = g.cur.fetchall()
self.conf_dic = {}
for conf in conf_array:
if conf[0] == 'STR':
self.conf_dic[conf[1]] = conf[2]
elif conf[0] == 'INT':
self.conf_dic[conf[1]] = int(conf[2])