NPI_install_youdao_lixian.bat
@echo off
start \\10.54.18.10\Software\IT-SOP\自助安装Windows\有道翻译离线.lnk
start \\10.54.18.10\Software\IT-SOP\自助安装Windows\获取有道翻译离线词典.lnk #不要这一句一执行了,,,把下面的py文件生成的exe另外来执行即可
因为用管理员来执行的话,有个问题,就是当前用户的目录是 C:/Users/管理员,,,,,,,而我们想要的是 C:/Users/当前用户,,所以这个不用管理员权限来执行
#自己亲自做的 有大用
#!/usr/bin/python3
#
import os
import requests
import zipfile
import getpass
import tkinter as tk
# 文件URL,请替换为实际的URL
# 下载后的临时文件名
temp_file_name = 'temp_download.zip'
# username = getpass.getuser()
username = os.environ.get('USERNAME') or os.environ.get('USERPROFILE').split('\\')[-1]
print(username)
# 目录的目标解压目录 C盘下的C:/Users/工号/AppData/Local/Yodao
extract_to_dir = f"C:/Users/{username}/AppData/Local/Yodao"
# temp_file_name = f"C:/{temp_file_name}"
def download_file(url, local_filename):
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
return local_filename
def unzip_file(zip_file_path, extract_to):
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
# 确保覆盖已存在的文件
for member in zip_ref.namelist():
zip_ref.extract(member, path=extract_to, pwd=None)
# 下载并解压文件
try:
if not os.path.exists(extract_to_dir):
os.makedirs(extract_to_dir)
downloaded_file_path = download_file(url, temp_file_name)
print(f"文件已下载到 {downloaded_file_path}")
# 解压文件到C盘下的C:/Users/工号/AppData/Local/Yodao,覆盖已存在的文件
unzip_file(downloaded_file_path, extract_to_dir)
print("文件已解压到C盘test目录,覆盖原有文件(如有)")
# 清理临时文件(可选)
#os.remove(downloaded_file_path)
#print("临时文件已删除")
root = tk.Tk()
root.title('复制有道翻译离线版词典')
label = tk.Label(root, text=" ")
label.pack()
label1 = tk.Label(root, text=f"成功复制有道翻译离线版词典!")
label1.pack()
btn = tk.Button(root, command=root.destroy)
btn["text"] = "确定"
btn.pack()
root.mainloop()
except Exception as e:
print(f"下载或解压过程中出错: {e}")
使用文心一言的代码
#!/usr/bin/python3
#
import requests
import zipfile
import io
import os
import getpass
import tkinter as tk
# 替换为你的ZIP文件URL
# 解压目标目录(C盘下的C:/Users/工号/AppData/Local/Yodao)
username = getpass.getuser()
unzip_dir = f"C:/Users/{username}/AppData/Local/Yodao"
# 确保目标目录存在
if not os.path.exists(unzip_dir):
os.makedirs(unzip_dir)
# 使用requests获取ZIP文件
response = requests.get(zip_url, stream=True)
# 检查请求是否成功
if response.status_code == 200:
# 使用with语句来确保ZIP文件在完成后被正确关闭
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
# 提取ZIP文件中的所有文件和目录,覆盖已存在的文件
zip_ref.extractall(unzip_dir)
print("ZIP文件已解压到:", unzip_dir)
root = tk.Tk()
root.title('复制有道翻译离线版词典')
label = tk.Label(root, text=" ")
label.pack()
label1 = tk.Label(root, text=f"成功复制有道翻译离线版词典!")
label1.pack()
btn = tk.Button(root, command=root.destroy)
btn["text"] = "确定"
btn.pack()
root.mainloop()
else:
print(f"下载ZIP文件失败。状态码: {response.status_code}")
exit()
使用通义的代码
#!/usr/bin/python3
#
import os
import requests
import zipfile
import getpass
import tkinter as tk
# 文件URL,请替换为实际的URL
# 下载后的临时文件名
temp_file_name = 'temp_download.zip'
# 目录的目标解压目录 C盘下的C:/Users/工号/AppData/Local/Yodao
username = getpass.getuser()
extract_to_dir = f"C:/Users/{username}/AppData/Local/Yodao"
def download_file(url, local_filename):
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
return local_filename
def unzip_file(zip_file_path, extract_to):
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
# 确保覆盖已存在的文件
for member in zip_ref.namelist():
zip_ref.extract(member, path=extract_to, pwd=None)
# 下载并解压文件
try:
if not os.path.exists(extract_to_dir):
os.makedirs(extract_to_dir)
downloaded_file_path = download_file(url, temp_file_name)
print(f"文件已下载到 {downloaded_file_path}")
# 解压文件到C盘下的C:/Users/工号/AppData/Local/Yodao,覆盖已存在的文件
unzip_file(downloaded_file_path, extract_to_dir)
print("文件已解压到C盘test目录,覆盖原有文件(如有)")
# 清理临时文件(可选)
os.remove(downloaded_file_path)
print("临时文件已删除")
root = tk.Tk()
root.title('复制有道翻译离线版词典')
label = tk.Label(root, text=" ")
label.pack()
label1 = tk.Label(root, text=f"成功复制有道翻译离线版词典!")
label1.pack()
btn = tk.Button(root, command=root.destroy)
btn["text"] = "确定"
btn.pack()
root.mainloop()
except Exception as e:
print(f"下载或解压过程中出错: {e}")