Skip to content

Commit

Permalink
Your commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Vstar authored and Amos Vstar committed Dec 28, 2024
1 parent a532c28 commit e9b2fd1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ def sort_dict(obj):
def subtract_rules(base_data, subtract_data):
"""从 base_data 中剔除 subtract_data 的规则"""
for key in ["process_name", "domain", "domain_suffix", "ip_cidr", "domain_regex"]:
base_set = set(base_data["rules"].get(key, []))
subtract_set = set(subtract_data["rules"].get(key, []))
base_data["rules"][key] = list(base_set - subtract_set)
# 确保 base_data["rules"] 和 subtract_data["rules"] 都是列表
base_set = set(base_data["rules"].get(key, [])) if isinstance(base_data["rules"], dict) else set(base_data["rules"])
subtract_set = set(subtract_data["rules"].get(key, [])) if isinstance(subtract_data["rules"], dict) else set(subtract_data["rules"])

# 更新 base_data["rules"][key] 为去重后的列表
base_data["rules"][key] = list(base_set - subtract_set)

def load_json( filepath):
def load_json(filepath):
"""加载 JSON 文件"""
with open(filepath, "r", encoding="utf-8") as f:
return json.load(f)
Expand Down

0 comments on commit e9b2fd1

Please sign in to comment.