Browse Source

读取配置文件,配置日志目录

master
zhangshu 8 months ago
parent
commit
c7ceb2ab89
  1. 15
      .vscode/launch.json
  2. 3
      Contant.py
  3. 6
      LoggerUtils.py
  4. 16
      init_channel.py
  5. 12
      init_channel_config.json

15
.vscode/launch.json

@ -0,0 +1,15 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "init channel",
"type": "debugpy",
"request": "launch",
"program": "init_channel.py",
"console": "integratedTerminal"
}
]
}

3
Contant.py

@ -0,0 +1,3 @@
db=""
logDir=""
logFileName=""

6
LoggerUtils.py

@ -0,0 +1,6 @@
from loguru import logger
Logger = logger
def initLogger(logDir,fileName):
path = "{}/{}".format(logDir,fileName)
logger.add(path+"/{time}.log", rotation="500MB", encoding="utf-8",
enqueue=True, compression="zip", retention="10 days")

16
init_channel.py

@ -0,0 +1,16 @@
from LoggerUtils import Logger, initLogger
from bs4 import BeautifulSoup as bs
from urllib.request import urlopen, Request
import json
import Contant
# py .\init.py --db=../db/youtube_prod.db --logDir=./logs
if __name__ == "__main__":
# 读取配置文件
with open('init_channel_config.json', 'r', encoding='utf-8') as f:
# 使用json.load()方法读取文件内容
data = json.load(f)
Contant.logDir = data['log']['dir']
Contant.logFileName = data['log']['fileName']
initLogger(Contant.logDir, Contant.logFileName)
Logger.info(data['mysql'])

12
init_channel_config.json

@ -0,0 +1,12 @@
{
"mysql": {
"host": "47.108.20.249",
"username": "root",
"password": "casino888!",
"database": "youtube"
},
"log": {
"dir": "./logs",
"fileName": "init_channel"
}
}
Loading…
Cancel
Save