|
@ -3,6 +3,8 @@ from bs4 import BeautifulSoup as bs |
|
|
from urllib.request import urlopen, Request |
|
|
from urllib.request import urlopen, Request |
|
|
import json |
|
|
import json |
|
|
import Contant |
|
|
import Contant |
|
|
|
|
|
import mysql.connector |
|
|
|
|
|
from mysql.connector import Error |
|
|
|
|
|
|
|
|
# py .\init.py --db=../db/youtube_prod.db --logDir=./logs |
|
|
# py .\init.py --db=../db/youtube_prod.db --logDir=./logs |
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
@ -10,7 +12,29 @@ if __name__ == "__main__": |
|
|
with open('init_channel_config.json', 'r', encoding='utf-8') as f: |
|
|
with open('init_channel_config.json', 'r', encoding='utf-8') as f: |
|
|
# 使用json.load()方法读取文件内容 |
|
|
# 使用json.load()方法读取文件内容 |
|
|
data = json.load(f) |
|
|
data = json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
# 初始化日志 |
|
|
Contant.logDir = data['log']['dir'] |
|
|
Contant.logDir = data['log']['dir'] |
|
|
Contant.logFileName = data['log']['fileName'] |
|
|
Contant.logFileName = data['log']['fileName'] |
|
|
initLogger(Contant.logDir, Contant.logFileName) |
|
|
initLogger(Contant.logDir, Contant.logFileName) |
|
|
Logger.info(data['mysql']) |
|
|
|
|
|
|
|
|
# 连接mysql |
|
|
|
|
|
dbHost = data['mysql']['host'] |
|
|
|
|
|
dbPort = data['mysql']['port'] |
|
|
|
|
|
dbUserName = data['mysql']['username'] |
|
|
|
|
|
dbPassword = data['mysql']['password'] |
|
|
|
|
|
dbDatabase = data['mysql']['database'] |
|
|
|
|
|
Logger.info("尝试连接mysql host:'{}' port:'{}' username:'{}' password:'{}' database:'{}'", |
|
|
|
|
|
dbHost, dbPort, dbUserName, dbPassword, dbDatabase) |
|
|
|
|
|
Contant.connection = None |
|
|
|
|
|
try: |
|
|
|
|
|
Contant.connection = mysql.connector.connect( |
|
|
|
|
|
host=dbHost, |
|
|
|
|
|
port=dbPort, |
|
|
|
|
|
user=dbUserName, |
|
|
|
|
|
passwd=dbPassword, |
|
|
|
|
|
database=dbDatabase |
|
|
|
|
|
) |
|
|
|
|
|
Logger.info("连接数据库成功") |
|
|
|
|
|
except Error as e: |
|
|
|
|
|
Logger.error(f"The error '{e}' occurred") |
|
|