57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import configparser
|
|
import threading
|
|
|
|
from flask import Flask
|
|
from webdriver_manager.chrome import ChromeDriverManager
|
|
import logging
|
|
|
|
from run_window import open_url_with_selenium
|
|
|
|
# 创建Flask应用
|
|
app = Flask(__name__)
|
|
|
|
# 读取配置文件
|
|
config = configparser.ConfigParser()
|
|
config.read('config.ini',encoding="utf-8")
|
|
|
|
# 从配置文件中读取参数
|
|
# 从配置文件中读取参数
|
|
url_base = config.get('base', 'url_base')
|
|
url_login = r"https://mozi-login.alibaba-inc.com/?APP_NAME=LPD_TEAM_AEOLUS&BACK_URL=https%3A%2F%2Faeolus.ele.me"
|
|
url_home = config.get('base', 'url_home')
|
|
url_work = config.get('base', 'url_work')
|
|
account = config.get('base', 'account')
|
|
password = config.get('base', 'password')
|
|
interval = int(config.get('base', 'interval'))
|
|
driver_type = config.get('base', 'driver')
|
|
host = config.get('web', 'host')
|
|
port = config.get('web', 'port')
|
|
debug = config.get('web', 'debug')
|
|
@app.route('/')
|
|
def hello_world():
|
|
return 'Hello World!'
|
|
|
|
if __name__ == '__main__':
|
|
# 设置日志记录级别
|
|
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
|
|
handler = logging.FileHandler('flask.log')
|
|
app.logger.addHandler(handler)
|
|
# 运行Flask应用
|
|
if debug.upper()=="FALSE":
|
|
debug = False
|
|
else:
|
|
debug = True
|
|
|
|
# 检查驱动
|
|
qd_path = ChromeDriverManager().install()
|
|
|
|
# 检查是否成功获取路径
|
|
if not qd_path:
|
|
app.logger.error("chrome驱动不存在")
|
|
else:
|
|
app.logger.info(f"Chromedriver 已安装在 {qd_path}")
|
|
# 异步执行selenium操作
|
|
threading.Thread(target=open_url_with_selenium, args=(url_base,)).start()
|
|
app.run(host=host,port=int(port),debug=debug)
|
|
app.logger.info(host+":"+port+" | debug = "+str(debug))
|