Skip to content

Commit

Permalink
修复 domain_suffix 逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Toperlock authored Dec 24, 2023
1 parent 0174773 commit 825a56b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ def parse_list_file(link, output_directory):
os.makedirs(output_directory, exist_ok=True)

result_rules = {"version": 1, "rules": []}
domain_entries = []

for pattern, addresses in df.groupby('pattern')['address'].apply(list).to_dict().items():
if pattern == 'domain_suffix':
rule_entry = {pattern: ['.' + address.strip() for address in addresses]}
result_rules["rules"].append(rule_entry)
domain_entries.extend([address.strip() for address in addresses])
elif pattern == 'domain':
domain_entries.extend([address.strip() for address in addresses])
else:
rule_entry = {pattern: [address.strip() for address in addresses]}
result_rules["rules"].append(rule_entry)
result_rules["rules"].append(rule_entry)
if domain_entries:
result_rules["rules"].insert(0, {'domain': domain_entries})

# 使用 output_directory 拼接完整路径
file_name = os.path.join(output_directory, f"{os.path.basename(link).split('.')[0]}.json")
Expand Down

0 comments on commit 825a56b

Please sign in to comment.