mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-12 23:30:44 +08:00
增加文件过滤功能
通过设置过滤规则,使用添加的过滤词汇来过滤不需要的文件。
This commit is contained in:
parent
fdb13e8257
commit
cd435a5818
20
app/run.py
20
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()
|
||||
|
||||
@ -274,6 +274,19 @@
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">过滤规则</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">过滤词汇</span>
|
||||
</div>
|
||||
<input type="text" name="filterwords[]" class="form-control" v-model="task.filterwords" placeholder="输入过滤词汇,用逗号分隔,例如:纯享,加更,超前企划">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">文件开始</label>
|
||||
<div class="col-sm-10">
|
||||
@ -421,6 +434,7 @@
|
||||
enddate: "",
|
||||
addition: {},
|
||||
ignore_extension: false,
|
||||
filterwords: "",
|
||||
runweek: [1, 2, 3, 4, 5, 6, 7]
|
||||
},
|
||||
run_log: "",
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user