raena-crawler-engine/tokopedia_crawler_engine/tokopedia_config.py

26 lines
672 B
Python

import json
from tokopedia_logger import logger
class Config():
config = None
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):
orig = super(Config, cls)
cls._instance = orig.__new__(cls, *args, **kw)
return cls._instance
def __init__(self):
if not self.config:
try:
logger.info("Loading config fine...")
with open("conf.json", "r") as jsonfile:
self.config = json.load(jsonfile)
logger.info("Config file loaded.")
except Exception as e:
logger.error("Cannot load config file. Please check. Exiting......")
exit(1)
def get(self):
return self.config