Added common module
This commit is contained in:
parent
03bc4bed24
commit
54663bdf48
25
hc_spider/common.py
Normal file
25
hc_spider/common.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import json
|
||||||
|
from functools import lru_cache
|
||||||
|
import logging
|
||||||
|
|
||||||
|
CONFIG_FILE = "config.json"
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def load_config() -> dict:
|
||||||
|
with open(CONFIG_FILE) as f:
|
||||||
|
config = json.load(f)
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger() -> logging.Logger:
|
||||||
|
logger = logging.getLogger("hc_spider")
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
handler = logging.StreamHandler()
|
||||||
|
formatter = logging.Formatter(
|
||||||
|
'%(asctime)s %(process)d %(processName)s %(thread)d %(threadName)s %(module)s %(levelname)s %(message)s')
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
return logger
|
Loading…
x
Reference in New Issue
Block a user