my_SD_mod / sd_yun /dingzhi.py
lang03383's picture
Update sd_yun/dingzhi.py
e7469e5 verified
raw
history blame
1.3 kB
import requests
from pathlib import Path
# 假设你有一个包含下载链接的 list
urls = [
'https://huggingface.co/lang03383/my_SD_mod/raw/main/sd_yun/config.json',
'https://huggingface.co/lang03383/my_SD_mod/raw/main/sd_yun/ui-config.json',
# 更多文件链接...
]
# 保存文件的根目录
save_dir = '/root/sdw/'
# 确保 save_dir 存在
Path(save_dir).mkdir(parents=True, exist_ok=True)
# 初始化下载成功标志
download_success = True
# 批量下载文件
for url in urls:
# 从 URL 中分解出文件名
filename = url.split('/')[-1]
# 完整的保存路径
save_path = Path(save_dir) / filename
try:
# 发起请求下载文件
response = requests.get(url)
response.raise_for_status() # 检查请求是否成功
# 写入文件到指定路径
with save_path.open('wb') as file:
file.write(response.content)
except requests.exceptions.RequestException as e:
# 下载失败,输出失败信息并更新标志
print(f"\033[91mFailed to download {url}: {e}\033[0m")
download_success = False
break # 停止后续下载
# 输出最终结果
if download_success:
print("\033[92mDownload Done!\033[0m")
else:
print("\033[91mDownload Failed!\033[0m")