diff --git a/app.py b/app.py index c34d71f71228df2d0bcc42acb516fae9b1dbf2a7..264fb2ab3c4732ba0ea4873ef7c0c2b3539fd3ce 100644 --- a/app.py +++ b/app.py @@ -29,7 +29,7 @@ app.config.from_object(config) # 单独的配置文件里写了,这里就不 db = SQLAlchemy(app) rule_list = getRules() -print(rule_list) +# print(rule_list) from models import * @@ -129,21 +129,6 @@ def getRules(path='cache'): rules = {'list': rule_list, 'count': len(rule_list)} return rules -def getHost(mode=0,port=None): - port = port or request.environ.get('SERVER_PORT') - hostname = socket.gethostname() - ip = socket.gethostbyname(hostname) - # ip = request.remote_addr - # print(ip) - # mode 为0是本地,1是局域网 2是线上 - if mode == 0: - host = f'localhost:{port}' - elif mode == 1: - host = f'{ip}:{port}' - else: - host = 'cms.nokia.press' - return host - @app.route('/favicon.ico') # 设置icon def favicon(): @@ -227,9 +212,7 @@ def database(): if __name__ == '__main__': - print(f'http://{getHost(1, 5705)}/index') # app.run(host="0.0.0.0", port=5705) # app.run(debug=True, host='0.0.0.0', port=5705) - print('http://localhost:5705/index') WSGIServer(('0.0.0.0', 5705), app).serve_forever() # WSGIServer(('0.0.0.0', 5705), app,log=None).serve_forever() \ No newline at end of file diff --git a/classes/cms.py b/classes/cms.py index ac6edfd8322c681794fdf63a7ab5bd14696bf146..fe6e68345c833c8de6e89f6707786742b3726a07 100644 --- a/classes/cms.py +++ b/classes/cms.py @@ -13,10 +13,15 @@ from utils.htmlParser import jsoup from urllib.parse import urljoin from concurrent.futures import ThreadPoolExecutor # 引入线程池 import logging +from js.rules import getRules _logger = logging.getLogger(__name__) - print(_logger) +rule_list = getRules() +print(rule_list) + +_logger.info('cms类装载完毕') +print(f'http://{getHost(1, 5705)}/index\nhttp://localhost:5705/index') class CMS: def __init__(self,rule,db=None,RuleClass=None): diff --git a/utils/web.py b/utils/web.py index d7cd20bae9f32ba44e04a5980fd65c07917d76fa..edd70e481c4957a324e940bedb392c8c96a47bda 100644 --- a/utils/web.py +++ b/utils/web.py @@ -4,6 +4,9 @@ # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------ # Date : 2022/8/25 +import socket +from flask import request + MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36' PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36' UA = 'Mozilla/5.0' @@ -12,3 +15,18 @@ headers = { 'Referer': 'https://www.baidu.com', 'user-agent': UA, } + +def getHost(mode=0,port=None): + port = port or request.environ.get('SERVER_PORT') + hostname = socket.gethostname() + ip = socket.gethostbyname(hostname) + # ip = request.remote_addr + # print(ip) + # mode 为0是本地,1是局域网 2是线上 + if mode == 0: + host = f'localhost:{port}' + elif mode == 1: + host = f'{ip}:{port}' + else: + host = 'cms.nokia.press' + return host \ No newline at end of file