MCPcopy Create free account
hub / github.com/Cats-Team/AdRules / process_rule

Function process_rule

script/sort.py:10–39  ·  view source on GitHub ↗
(file_path)

Source from the content-addressed store, hash-verified

8 print(f"[INFO] {timestamp} - {message}")
9
10def process_rule(file_path):
11 if not os.path.exists(file_path):
12 log(f"错误: 文件未找到 - {file_path}")
13 return
14
15 try:
16
17 # 读取文件
18 with open(file_path, 'r', encoding='utf-8') as f:
19 lines = f.readlines()
20
21 raw_count = len(lines)
22 if raw_count == 0:
23 log("文件为空,跳过处理。")
24 return
25
26 # 核心逻辑:去重并排序
27 unique_lines = sorted(set(lines))
28 final_count = len(unique_lines)
29 removed_count = raw_count - final_count
30
31 # 写入结果
32 with open(file_path, 'w', encoding='utf-8') as f:
33 f.writelines(unique_lines)
34
35 # 输出统计结果
36 log(f"排序完成 - {raw_count} > {final_count} (移除 {removed_count} 重复项)")
37
38 except Exception as e:
39 log(f"处理异常: {e}")
40
41if __name__ == "__main__":
42 parser = argparse.ArgumentParser(description="规则去重工具")

Callers 1

sort.pyFile · 0.85

Calls 1

logFunction · 0.85

Tested by

no test coverage detected