From 72e11600c92b83956378bfea3334b139bf884eca Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Sat, 27 Aug 2022 00:35:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=9F=A5=E7=9C=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 28 +++++++++++++++----- pycms.json | 2 +- pycms2.json | 2 +- templates/index.html | 23 ++++++++++++++--- templates/raw.html | 61 ++++++++++++++++++++++++++++++++++++++++++++ utils/parser.py | 5 ++-- 6 files changed, 107 insertions(+), 14 deletions(-) create mode 100644 templates/raw.html diff --git a/app.py b/app.py index 80a56bf..19cdb10 100644 --- a/app.py +++ b/app.py @@ -102,19 +102,33 @@ def clear(): os.remove(cache_path) return jsonify(error.success('成功删除文件:'+cache_path)) -@app.route('/rules') -def rules(): - # base_path = os.path.dirname(os.path.abspath(__file__))+'cache' # 当前文件所在目录 +def getRules(): base_path = 'cache/' # 当前文件所在目录 print(base_path) file_name = os.listdir(base_path) file_name = list(filter(lambda x: str(x).endswith('.js'), file_name)) # print(file_name) rule_list = [file.replace('.js', '') for file in file_name] - rules = {'list':rule_list,'count':len(rule_list)} - # print(rule_list) - # return jsonify(obj) - return render_template('rules.html',rules=rules) + rules = {'list': rule_list, 'count': len(rule_list)} + return rules + +@app.route('/rules') +def rules(): + return render_template('rules.html',rules=getRules()) + +@app.route('/raw') +def rules_raw(): + return render_template('raw.html',rules=getRules()) + +@app.route("/plugin/",methods=['GET']) +def plugin(name): + # name=道长影视模板.js + if not name or not name.split('.')[-1] in ['js','txt','py','json']: + return jsonify(error.failed(f'非法威胁,未指定文件名。必须包含js|txt|json|py')) + try: + return parser.toJs(name) + except Exception as e: + return jsonify(error.failed(f'非法猥亵\n{e}')) if __name__ == '__main__': diff --git a/pycms.json b/pycms.json index 743d3b1..865e788 100644 --- a/pycms.json +++ b/pycms.json @@ -47,7 +47,7 @@ "key":"dr_ckmv", "name":"cokemv(道长)", "type":1, - "api":"http://cms.nokia.press/vod?rule=cokemv", + "api":"http://cms.nokia.press/vod?rule=cokemv&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/cokemv.js", "searchable": 1, "quickSearch": 1, "filterable": 1 diff --git a/pycms2.json b/pycms2.json index 03f5db0..c2806ea 100644 --- a/pycms2.json +++ b/pycms2.json @@ -48,7 +48,7 @@ "key":"dr_ckmv", "name":"cokemv(道长)", "type":1, - "api":"http://localhost:5705/vod?rule=cokemv", + "api":"http://localhost:5705/vod?rule=cokemv&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/cokemv.js", "searchable": 1, "quickSearch": 1, "filterable": 1 diff --git a/templates/index.html b/templates/index.html index 695989b..fb5e80a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,14 +8,31 @@ dr_py首页 +

欢迎使用dr_py项目

可以简单的自定义爬虫实现cms数据接口

-
+ -
- 缓存文件列表 + + \ No newline at end of file diff --git a/templates/raw.html b/templates/raw.html new file mode 100644 index 0000000..6cfe6ee --- /dev/null +++ b/templates/raw.html @@ -0,0 +1,61 @@ + + + + + + + + + 已缓存规则列表-{{rules.count}} + + + + + +{% if rules.count < 1 %} +

暂无已缓存的规则

+{% endif %} + +{% for rule in rules.list %} + + {% if rule|length > 2 %} + +
  • + + {{ rule }} +
  • + + {% else %} + +
  • + {{ rule }} +
  • + + {% endif %} + + + {% endfor %} + + + \ No newline at end of file diff --git a/utils/parser.py b/utils/parser.py index e3cb7ca..4552ba4 100644 --- a/utils/parser.py +++ b/utils/parser.py @@ -48,7 +48,8 @@ def runJs(jsPath): def toJs(jsPath): base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 - js_path = os.path.join(base_path, jsPath) + js_path = os.path.join(base_path, f'cache/{jsPath}') + print(js_path) if not os.path.exists(js_path): return jsonify({'code': -2, 'msg': f'非法猥亵,文件不存在'}) with open(js_path, 'r', encoding='UTF-8') as fp: @@ -59,7 +60,7 @@ def toJs(jsPath): def toHtml(jsPath): base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 - js_path = os.path.join(base_path, jsPath) + js_path = os.path.join(base_path, f'cache/{jsPath}') with open(js_path, 'r', encoding='UTF-8') as fp: js = fp.read() response = make_response(js) -- GitLab