Create dingzhi.py
Browse files- sd_yun/dingzhi.py +47 -0
sd_yun/dingzhi.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
# 假设你有一个包含下载链接的 list
|
5 |
+
urls = [
|
6 |
+
'https://raw.githubusercontent.com/Efan3536/sdyun/main/config.json',
|
7 |
+
'https://raw.githubusercontent.com/Efan3536/sdyun/main/ui-config.json',
|
8 |
+
# 更多文件链接...
|
9 |
+
]
|
10 |
+
|
11 |
+
# 保存文件的根目录
|
12 |
+
save_dir = '/root/sdw/'
|
13 |
+
|
14 |
+
# 确保 save_dir 存在
|
15 |
+
Path(save_dir).mkdir(parents=True, exist_ok=True)
|
16 |
+
|
17 |
+
# 初始化下载成功标志
|
18 |
+
download_success = True
|
19 |
+
|
20 |
+
# 批量下载文件
|
21 |
+
for url in urls:
|
22 |
+
# 从 URL 中分解出文件名
|
23 |
+
filename = url.split('/')[-1]
|
24 |
+
|
25 |
+
# 完整的保存路径
|
26 |
+
save_path = Path(save_dir) / filename
|
27 |
+
|
28 |
+
try:
|
29 |
+
# 发起请求下载文件
|
30 |
+
response = requests.get(url)
|
31 |
+
response.raise_for_status() # 检查请求是否成功
|
32 |
+
|
33 |
+
# 写入文件到指定路径
|
34 |
+
with save_path.open('wb') as file:
|
35 |
+
file.write(response.content)
|
36 |
+
|
37 |
+
except requests.exceptions.RequestException as e:
|
38 |
+
# 下载失败,输出失败信息并更新标志
|
39 |
+
print(f"\033[91mFailed to download {url}: {e}\033[0m")
|
40 |
+
download_success = False
|
41 |
+
break # 停止后续下载
|
42 |
+
|
43 |
+
# 输出最终结果
|
44 |
+
if download_success:
|
45 |
+
print("\033[92mDownload Done!\033[0m")
|
46 |
+
else:
|
47 |
+
print("\033[91mDownload Failed!\033[0m")
|