Update process_blacklist.py
This commit is contained in:
parent
f76b3791ef
commit
6bb23c97f2
|
@ -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",
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue