-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.py
38 lines (29 loc) · 967 Bytes
/
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
import logging
import os
import config_secrets as secrets
class Config:
is_test_env = False
@classmethod
def required_get(cls, env, key):
if cls.is_test_env:
return ""
v = env.get(key) or getattr(secrets, key)
if not v:
raise KeyError(key)
else:
return v
@classmethod
def get(cls, env, key):
v = env.get(key) or getattr(secrets, key)
if not v:
logging.warn("Env[{}] not loaded.".format(key))
return None
else:
return v
def __init__(self, env, is_test_env=False):
Config.is_test_env = is_test_env
self.bot_id = Config.required_get(env, "BOT_ID")
self.bot_token = Config.required_get(env, "BOT_TOKEN")
self.covid19_api_token = Config.get(env, "COVID19_API_TOKEN") or ""
self.pingpong_api_token = Config.get(env, "PINGPONG_API_TOKEN") or ""
config = Config(os.environ)