-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
60 lines (49 loc) · 1.52 KB
/
helpers.py
File metadata and controls
60 lines (49 loc) · 1.52 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
import os
import yaml
class AppConfig(object):
DB_URL_TEMPLATE = "{}://{}:{}@{}:{}/{}"
def __init__(self, db_type,
db_host, db_port, db_name,
db_username, db_password,
file_in_dir, file_out_dir,
posts_dir):
self.db_type = db_type
self.db_host = db_host
self.db_port = db_port
self.db_name = db_name
self.db_username = db_username
self.db_password = db_password
self.file_in_dir = file_in_dir
self.file_out_dir = file_out_dir
self.posts_dir = posts_dir
def get_db_url(self):
return AppConfig.DB_URL_TEMPLATE.format(
self.db_type,
self.db_username,
self.db_password,
self.db_host,
self.db_port,
self.db_name
)
class AppConfigParser(object):
""" IG App Config Parser
only accept yml format
"""
def __init__(self):
self._config_file_path = os.getenv(
'IG_CONF_PATH',
'config.yml'
)
def parse(self):
_config = yaml.load(
open(self._config_file_path, 'r')
)
return AppConfig(**_config)
if __name__ == '__main__':
""" for running simple tests """
app_conf_parser = AppConfigParser()
app_conf = app_conf_parser.parse()
assert app_conf.db_host == 'localhost'
assert app_conf.db_type == 'postgresql'
assert app_conf.get_db_url() \
== 'postgresql://postgres:postgres@localhost:5432/ig'