提交 33224bc7 编写于 作者: H hjdhnx

增加了清缓存的操作

上级 053577e4
......@@ -13,7 +13,7 @@ import codecs
from models.cms import CMS
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
app = Flask(__name__)
app = Flask(__name__,static_folder='static',static_url_path='/static')
app.config["JSON_AS_ASCII"] = False # jsonify返回的中文正常显示
from utils.web import *
rule_list = getRules()
......@@ -102,6 +102,21 @@ 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' # 当前文件所在目录
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)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5705)
# app.run(debug=True, host='0.0.0.0', port=5705)
\ No newline at end of file
......@@ -9,7 +9,7 @@
- [X] 6.增加homeUrl和host参数,以及class_parse参数,可以动态定位分类标签
- [X] 7.获取二级详情函数增加了线程池的使用
- [ ] 8.模板自定义filter过滤
- [ ] 9.网页端显示缓存的规则以及提供点击清除缓存操作
- [X] 9.网页端显示缓存的规则以及提供点击清除缓存操作
###### 特性说明
1. 参考了海阔视界dr模板设计思路
2. 参考tv_box的t4项目思路重新设计了cms接口
......
此差异已折叠。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-siteapp;no-transform">
<meta name="applicable-device" content="pc,mobile">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>dr_py首页</title>
</head>
<body>
<h1>欢迎使用dr_py项目</h1>
<p>可以简单的自定义爬虫实现cms数据接口</p>
<a href="/clear?rule=">缓存清理接口</a>
<div>
<a href="/clear?rule=">缓存清理接口</a>
</div>
<div>
<a href="/rules">缓存文件列表</a>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-siteapp;no-transform">
<meta name="applicable-device" content="pc,mobile">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>已缓存规则列表-{{rules.count}}</title>
<script src="/static/js/jquery.min.js"></script>
</head>
<style>
.red {
color:red;
font-weight: bold
}
.yellow {
color:yellow;
font-weight: bold
}
.refresh{
}
</style>
<body>
<script>
$(document).ready(function(){
$(".refresh").click(function(){
// location.reload();
let rule = this.innerText.trim();
let code = $.ajax({url:"/clear?rule="+rule,async:false}).responseText;
code = typeof(code) === "object"?code:JSON.parse(code);
if(code.code === 200){
alert(code.msg);
location.reload()
}
});
});
</script>
{% if rules.count < 1 %}
<h3>暂无已缓存的规则</h3>
{% endif %}
{% for rule in rules.list %}
{% if rule|length > 2 %}
<!-- | 为过滤条件 -->
<li class="red">
<!-- <a class="refresh" href="/clear?rule={{rule}}" target="_blank">{{ rule }}</a>-->
<a class="refresh" href="javascript:void(0);">{{ rule }}</a>
</li>
{% else %}
<!-- 如果是if条件,最后必须要有else,否则就会报错 -->
<li class="yellow">
<a class="refresh" href="javascript:void(0);" target="_blank">{{ rule }}</a>
</li>
{% endif %}
<!-- if条件必须有endif,否则会报错 -->
{% endfor %}
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册