update
This commit is contained in:
30
downloads_update_now.py
Normal file
30
downloads_update_now.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
url = 'https://api.github.com/repos/dengrb1/chatgpt/releases/latest'
|
||||||
|
|
||||||
|
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
||||||
|
release_info = json.loads(response.text)
|
||||||
|
|
||||||
|
new_version = release_info['tag_name']
|
||||||
|
current_version = '1.3' # 修改为你的已有版本号
|
||||||
|
|
||||||
|
if new_version != current_version:
|
||||||
|
print('发现新版本: {}'.format(new_version))
|
||||||
|
print('准备更新')
|
||||||
|
|
||||||
|
# 下载最新程序并保存到本地
|
||||||
|
download_url = release_info['assets'][0]['browser_download_url'] # 假设发布包第一个asset为我们要下载的程序
|
||||||
|
file_name = download_url.split('/')[-1]
|
||||||
|
file_path = os.path.join(os.getcwd(), file_name)
|
||||||
|
|
||||||
|
print('开始下载:{}'.format(file_name))
|
||||||
|
response = requests.get(download_url)
|
||||||
|
with open(file_path, 'wb') as f:
|
||||||
|
f.write(response.content)
|
||||||
|
print('下载完成!')
|
||||||
|
# 打开更新程序
|
||||||
|
os.startfile(file_path)
|
||||||
|
else:
|
||||||
|
print('当前已是最新版本')
|
||||||
32
update.pyw
32
update.pyw
@@ -10,6 +10,7 @@ import requests
|
|||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
|
ml = os.getcwd()
|
||||||
|
|
||||||
def quit_exe():
|
def quit_exe():
|
||||||
root.destroy()
|
root.destroy()
|
||||||
@@ -17,32 +18,11 @@ def update_now():
|
|||||||
webbrowser.open("https://kgithub.com/dengrb1/chatgpt/releases/")
|
webbrowser.open("https://kgithub.com/dengrb1/chatgpt/releases/")
|
||||||
messagebox.showinfo('update', '请选择最新版本并下载运行安装程序,然后就可以更新了!')
|
messagebox.showinfo('update', '请选择最新版本并下载运行安装程序,然后就可以更新了!')
|
||||||
def downloads_update_now():
|
def downloads_update_now():
|
||||||
url = 'https://api.github.com/repos/dengrb1/chatgpt/releases/latest'
|
if os.path.exists(os.path.join(ml, "downloads_update_now.exe")):
|
||||||
|
os.startfile("downloads_update_now")
|
||||||
response = requests.get(url, headers={'Accept': 'application/vnd.github.v3+json'})
|
|
||||||
release_info = json.loads(response.text)
|
|
||||||
|
|
||||||
new_version = release_info['tag_name']
|
|
||||||
current_version = '1.3' # 修改为你的已有版本号
|
|
||||||
|
|
||||||
if new_version != current_version:
|
|
||||||
messagebox.showinfo('在线更新','发现新版本: {}'.format(new_version))
|
|
||||||
messagebox.showinfo('在线更新','准备更新')
|
|
||||||
|
|
||||||
# 下载最新程序并保存到本地
|
|
||||||
download_url = release_info['assets'][0]['browser_download_url'] # 假设发布包第一个asset为我们要下载的程序
|
|
||||||
file_name = download_url.split('/')[-1]
|
|
||||||
file_path = os.path.join(os.getcwd(), file_name)
|
|
||||||
|
|
||||||
print('开始下载:{}'.format(file_name))
|
|
||||||
response = requests.get(download_url)
|
|
||||||
with open(file_path, 'wb') as f:
|
|
||||||
f.write(response.content)
|
|
||||||
print('下载完成!')
|
|
||||||
# 打开更新程序
|
|
||||||
os.startfile(file_path)
|
|
||||||
else:
|
else:
|
||||||
messagebox.showinfo('在线更新','当前已是最新版本')
|
messagebox.showerror(':( error','在线更新模块错误:文件不存在')
|
||||||
|
|
||||||
|
|
||||||
# Label
|
# Label
|
||||||
update_now_bt = Button(root ,text='在线更新', command=update_now).pack(side=RIGHT)
|
update_now_bt = Button(root ,text='在线更新', command=update_now).pack(side=RIGHT)
|
||||||
@@ -73,7 +53,7 @@ text_box.configure(state='disabled')
|
|||||||
|
|
||||||
# Button
|
# Button
|
||||||
quit_bt = Button(root, text='返回', command=quit_exe).pack()
|
quit_bt = Button(root, text='返回', command=quit_exe).pack()
|
||||||
update_now_bt = Button(root, text='在线更新')
|
update_now_bt = Button(root, text='在线更新', command=downloads_update_now).pack()
|
||||||
|
|
||||||
# mainloop
|
# mainloop
|
||||||
root.title('更新日志')
|
root.title('更新日志')
|
||||||
|
|||||||
Reference in New Issue
Block a user