-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
34 lines (30 loc) · 1.27 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
import toml
import serp
import importlib
class AppConfig:
def __init__(self, config_path="config.toml"):
with open(config_path, "r") as f:
config = toml.load(f)
if "app" in config:
self.default_query = config["app"]["default_query"]
self.page_title = config["app"]["page_title"]
self.render_serp_item = getattr(serp, config["app"]["serp_renderer"])
else:
raise ValueError("missing app config")
if "parser" in config:
parts = config["parser"]["class"].split(".")
module = importlib.import_module(".".join(parts[:-1]))
cls = getattr(module, parts[-1])
parse_args = config["parser"]["parser_args"]
self.parser = cls(**parse_args)
else:
raise ValueError("missing parser config")
if "indexer" in config:
parts = config["indexer"]["class"].split(".")
module = importlib.import_module(".".join(parts[:-1]))
cls = getattr(module, parts[-1])
indexer_path = config["indexer"]["path"]
indexer_args = config["indexer"]["indexer_args"]
self.indexer = cls(indexer_path, **indexer_args)
else:
raise ValueError("missing indexer config")