From 309c4af69c6909758a1844c53f7d6bf220b4586d Mon Sep 17 00:00:00 2001 From: Ryan-the-hito <95213517+Ryan-the-hito@users.noreply.github.com> Date: Tue, 5 Mar 2024 20:43:01 +0800 Subject: [PATCH] Updated v2.0.4 --- Strawberry/Strawberry.py | 82 +++++++++++++++++++++++++++++++++----- Strawberry/Strawberry.spec | 2 +- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/Strawberry/Strawberry.py b/Strawberry/Strawberry.py index be24969..f268509 100755 --- a/Strawberry/Strawberry.py +++ b/Strawberry/Strawberry.py @@ -32,6 +32,11 @@ import asyncio import json import mistune +import urllib3 +import logging +import requests +import html2text +from bs4 import BeautifulSoup app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(False) @@ -157,7 +162,7 @@ def setUpMainWindow(self): widg2.setLayout(blay2) widg3 = QWidget() - lbl1 = QLabel('Version 2.0.3', self) + lbl1 = QLabel('Version 2.0.4', self) blay3 = QHBoxLayout() blay3.setContentsMargins(0, 0, 0, 0) blay3.addStretch() @@ -620,25 +625,31 @@ def __init__(self): def initUI(self): # 说明页面内信息 - lbl = QLabel('Current Version: 2.0.3', self) - lbl.move(110, 75) + self.lbl = QLabel('Current Version: v2.0.4', self) + self.lbl.move(30, 45) - lbl0 = QLabel('Check Now:', self) - lbl0.move(30, 20) + lbl0 = QLabel('Download Update:', self) + lbl0.move(30, 75) - bt1 = QPushButton('Github', self) + lbl1 = QLabel('Latest Version:', self) + lbl1.move(30, 15) + + self.lbl2 = QLabel('', self) + self.lbl2.move(122, 15) + + bt1 = QPushButton('Google Drive', self) bt1.setFixedWidth(120) bt1.clicked.connect(self.upd) - bt1.move(110, 15) + bt1.move(150, 75) bt2 = QPushButton('Dropbox', self) bt2.setFixedWidth(120) bt2.clicked.connect(self.upd2) - bt2.move(110, 45) + bt2.move(150, 105) - self.resize(300, 110) + self.resize(300, 150) self.center() - self.setWindowTitle('Check for Updates') + self.setWindowTitle('Strawberry Updates') self.setFocus() self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint) @@ -656,6 +667,54 @@ def center(self): # 设置窗口居中 def activate(self): # 设置窗口显示 self.show() + self.checkupdate() + + def checkupdate(self): + targetURL = 'https://github.com/Ryan-the-hito/Strawberry/releases' + try: + # Fetch the HTML content from the URL + urllib3.disable_warnings() + logging.captureWarnings(True) + s = requests.session() + s.keep_alive = False # 关闭多余连接 + response = s.get(targetURL, verify=False) + response.encoding = 'utf-8' + html_content = response.text + # Parse the HTML using BeautifulSoup + soup = BeautifulSoup(html_content, "html.parser") + # Remove all images from the parsed HTML + for img in soup.find_all("img"): + img.decompose() + # Convert the parsed HTML to plain text using html2text + text_maker = html2text.HTML2Text() + text_maker.ignore_links = True + text_maker.ignore_images = True + plain_text = text_maker.handle(str(soup)) + # Convert the plain text to UTF-8 + plain_text_utf8 = plain_text.encode(response.encoding).decode("utf-8") + + for i in range(10): + plain_text_utf8 = plain_text_utf8.replace('\n\n\n\n', '\n\n') + plain_text_utf8 = plain_text_utf8.replace('\n\n\n', '\n\n') + plain_text_utf8 = plain_text_utf8.replace(' ', ' ') + plain_text_utf8 = plain_text_utf8.replace(' ', ' ') + + pattern2 = re.compile(r'(v\d+\.\d+\.\d+)\sLatest') + result = pattern2.findall(plain_text_utf8) + result = ''.join(result) + nowversion = self.lbl.text().replace('Current Version: ', '') + if result == nowversion: + alertupdate = result + '. You are up to date!' + self.lbl2.setText(alertupdate) + self.lbl2.adjustSize() + else: + alertupdate = result + ' is ready!' + self.lbl2.setText(alertupdate) + self.lbl2.adjustSize() + except: + alertupdate = 'No Intrenet' + self.lbl2.setText(alertupdate) + self.lbl2.adjustSize() class CustomDialog_warn(QDialog): # 提醒检查路径 @@ -8958,6 +9017,9 @@ def addcit2(self): self.leii2.clear() + with open(BasePath + 'filename.txt', 'w', encoding='utf-8') as f0: + f0.write('') + def clinp(self): if self.textii2.toPlainText() != '' and self.leii1.text() != '': path1 = codecs.open(BasePath + 'path_scr.txt', 'r', encoding='utf-8').read() diff --git a/Strawberry/Strawberry.spec b/Strawberry/Strawberry.spec index 9b5bf66..a799a7d 100644 --- a/Strawberry/Strawberry.spec +++ b/Strawberry/Strawberry.spec @@ -3,7 +3,7 @@ block_cipher = None -__version__ = '2.0.3' +__version__ = '2.0.4' a = Analysis(