File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 1+ from typing import LiteralString
12import requests
23from datetime import datetime
34
45# 要下载的文件链接列表
56urls = [
67 "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt" ,
78 "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all_ip.txt" ,
9+ "https://cf.trackerslist.com/all.txt"
810]
911
1012# 下载文件并保存到内存中
@@ -13,19 +15,20 @@ def download_file(url):
1315 return response .content
1416
1517# 合并文件并去除空行
16- def merge_files (contents ) :
17- merged_content = ""
18- for content in contents :
19- lines = content .decode ().split ("\n " )
18+ def merge_files (contents : list ) -> str :
19+ _content : set = set () # 创建一个空的集合,达到去重的作用
20+ for content in contents : # contents: list : [str\n\n, str\n\n]
21+ lines : list = content .decode ().split ("\n " ) # content: str : str\n
2022 for line in lines :
2123 line = line .strip () # 去除首尾空格和换行符
2224 if line : # 如果不是空行则加入合并内容
23- merged_content += line + "\n "
25+ _content .add (line )
26+ merged_content = "\n " .join (_content ) + "\n "
2427 return merged_content
2528
2629# 下载文件并保存到内存中
27- file_contents = []
28- for url in urls :
30+ file_contents : list = []
31+ for i , url in enumerate ( urls ) :
2932 file_content = download_file (url )
3033 file_contents .append (file_content )
3134
You can’t perform that action at this time.
0 commit comments