diff --git a/process_blacklist.py b/process_blacklist.py index 632d7ca..a8d1786 100644 --- a/process_blacklist.py +++ b/process_blacklist.py @@ -1,10 +1,11 @@ +import gzip import ipaddress import re import requests -def process_blacklist(url, output_file): +def process_blacklist(url, output_file_name): response = requests.get(url) lines = response.text.splitlines() @@ -25,13 +26,17 @@ def process_blacklist(url, output_file): ip_range = f"{line}-{line}" processed_lines.append(f"pbt:{ip_range}") - with open(output_file, "w", encoding="utf-8") as file: + with open(f"{output_file_name}.txt", "w", encoding="utf-8") as file: + for line in processed_lines: + file.write(line + "\n") + + with gzip.open(f"{output_file_name}.gz", "wt", encoding="utf-8") as file: for line in processed_lines: file.write(line + "\n") -# 调用函数处理远程文件 +# 调用函数处理远程文件并压缩为.gz格式 process_blacklist( "https://raw.githubusercontent.com/PBH-BTN/BTN-Collected-Rules/main/combine/all.txt", - "transmission_blacklist.txt", + "transmission_blacklist", )