From 66274a13309a6a6eacc7958b67eb89380a1f6437 Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Sat, 27 Aug 2022 15:27:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 19 +------------------ classes/cms.py | 7 ++++++- utils/web.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app.py b/app.py index c34d71f..264fb2a 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 ac6edfd..fe6e683 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 d7cd20b..edd70e4 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 -- GitLab