From cd435a5818d4720796aeaf98dcb4b7144b9f480b Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Mon, 31 Mar 2025 02:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过设置过滤规则,使用添加的过滤词汇来过滤不需要的文件。 --- app/run.py | 20 ++++++++++++++++++++ app/templates/index.html | 14 ++++++++++++++ quark_auto_save.py | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/app/run.py b/app/run.py index ae22fe1..f36dbce 100644 --- a/app/run.py +++ b/app/run.py @@ -348,6 +348,26 @@ def init(): write_json(data) +def filter_files(files, filterwords): + if not filterwords: + return files + filterwords_list = [word.strip() for word in filterwords.split(',')] + return [file for file in files if not any(word in file['file_name'] for word in filterwords_list)] + + +@app.route("/get_filtered_files") +def get_filtered_files(): + if not is_login(): + return jsonify({"error": "未登录"}) + data = read_json() + filterwords = request.args.get("filterwords", "") + account = Quark(data["cookie"][0], 0) + fid = request.args.get("fid", 0) + files = account.ls_dir(fid) + filtered_files = filter_files(files, filterwords) + return jsonify(filtered_files) + + if __name__ == "__main__": init() reload_tasks() diff --git a/app/templates/index.html b/app/templates/index.html index 30b4a7e..1cf73de 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -274,6 +274,19 @@ + +
+ +
+
+
+ 过滤词汇 +
+ +
+
+
+
@@ -421,6 +434,7 @@ enddate: "", addition: {}, ignore_extension: false, + filterwords: "", runweek: [1, 2, 3, 4, 5, 6, 7] }, run_log: "", diff --git a/quark_auto_save.py b/quark_auto_save.py index 4ae26ca..be5f508 100644 --- a/quark_auto_save.py +++ b/quark_auto_save.py @@ -645,6 +645,12 @@ class Quark: pwd_id, stoken, share_file_list[0]["fid"] )["list"] + # 应用过滤词过滤文件 + if task.get("filterwords"): + filterwords_list = [word.strip() for word in task["filterwords"].split(',')] + share_file_list = [file for file in share_file_list if not any(word in file['file_name'] for word in filterwords_list)] + print(f"📑 应用过滤词:{task['filterwords']},剩余{len(share_file_list)}个文件") + # 获取目标目录文件列表 savepath = re.sub(r"/{2,}", "/", f"/{task['savepath']}{subdir_path}") if not self.savepath_fid.get(savepath):