File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import requests
2+
3+ # 要下载的文件链接列表
4+ urls = [
5+ "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt" ,
6+ "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all_ip.txt" ,
7+ ]
8+
9+ # 下载文件并保存到内存中
10+ def download_file (url ):
11+ response = requests .get (url )
12+ return response .content
13+
14+ # 合并文件并去除空行
15+ def merge_files (contents ):
16+ merged_content = ""
17+ for content in contents :
18+ lines = content .decode ().split ("\n " )
19+ for line in lines :
20+ line = line .strip () # 去除首尾空格和换行符
21+ if line : # 如果不是空行则加入合并内容
22+ merged_content += line + "\n "
23+ return merged_content
24+
25+ # 下载文件并保存到内存中
26+ file_contents = []
27+ for url in urls :
28+ file_content = download_file (url )
29+ file_contents .append (file_content )
30+
31+ # 合并文件并去除空行
32+ merged_content = merge_files (file_contents )
33+
34+ # 保存合并结果到文件
35+ output_file = "trackerslist.txt"
36+ with open (output_file , "w" ) as file :
37+ file .write (merged_content )
38+
39+ print (f"文件已合并为 { output_file } " )
You can’t perform that action at this time.
0 commit comments