-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
113 lines (66 loc) · 2.19 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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import logging
base_dir = os.path.abspath(os.path.dirname(__file__))
formatter = logging.Formatter("%(levelname)s :: %(message)s :: %(asctime)s")
def logger_setup(name, file, level=logging.INFO):
handler = logging.FileHandler(file)
handler.setFormatter(formatter)
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(handler)
return logger
class Config:
SECRETE_KEY = os.getenv("SECRETE_KEY")
MPESA_BASE_URL = "https://sandbox.safaricom.co.ke"
INITIATOR_NAME = os.environ.get("INITIATOR_NAME")
INITIATOR_PASSWORD = os.environ.get("INITIATOR_PASSWORD")
BUSINESS_SHORT_CODE = os.environ.get("BUSINESS_SHORT_CODE")
PASS_KEY = os.environ.get("PASS_KEY")
ACTIVATION_AMOUNT = os.environ.get("ACTIVATION_AMOUNT")
@staticmethod
def init_app(app):
from app.models import Account
from sqlalchemy import event
def inject_app_obj(func):
setattr(
func,
"_current_app",
app
)
return func
event.listen(
Account.balance,
"set",
inject_app_obj(Account.balance_notify)
)
event.listen(
Account.status_id,
"set",
inject_app_obj(Account.status_report_notify)
)
class Development(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URI") or \
"sqlite:///" + os.path.join(base_dir, "dev-data.sqlite")
MPESA_PHONENUMBER = os.environ.get("MPESA_PHONENUMBER")
@staticmethod
def init_app(app):
Config.init_app(app=app)
class Testing(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URI") or \
"sqlite:///" + os.path.join(base_dir, "test-data.sqlite")
MPESA_PHONENUMBER = os.environ.get("MPESA_PHONENUMBER")
@staticmethod
def init_app(app):
Config.init_app(app=app)
class Production(Config):
@staticmethod
def init__app(app):
Config.init_app(app=app)
config = {
"default":Development,
"development":Development,
"testing":Testing,
"production":Production
}