Update process_blacklist.py

This commit is contained in:
jqtmviyu 2024-07-30 11:02:10 +08:00 committed by GitHub
parent f76b3791ef
commit 6bb23c97f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -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",
)