From f2dcc987ffb0278e678c2d5b58d2192c7c2282d9 Mon Sep 17 00:00:00 2001 From: LanYunDev <95263282+LanYunDev@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:43:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DmacOS=E4=B8=8A=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=8A=A5=E9=94=99=20=E6=9B=B4=E6=96=B0=E4=BE=9D?= =?UTF-8?q?=E8=B5=96,=E8=A7=A3=E5=86=B3=E6=8A=A5=E9=94=99=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81macOS=E8=87=AA=E5=8A=A8=E5=AE=89=E8=A3=85zbar=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=20=E5=9C=A8Linux=E4=B8=8A=E5=AE=9E=E7=8E=B0pause?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 5 ++++- requirements.txt | 14 +++++++------- util/LoginUtil.py | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index f08ce99..ca368fc 100644 --- a/main.py +++ b/main.py @@ -190,7 +190,10 @@ def save_data(): current_directory = os.getcwd() # os.startfile(current_directory + user_save_path[1:]) open_file(current_directory + user_save_path[1:]) - os.system('pause') + if platform.system() == 'Windows': + os.system('pause') + else: + os.system('stty raw -echo;dd bs=1 count=1 >/dev/null 2>&1;stty cooked echo') # 打开文件展示 diff --git a/requirements.txt b/requirements.txt index 0e99343..04d1b16 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ beautifulsoup4==4.12.3 -pandas==2.2.0 -tqdm==4.66.2 -requests==2.31.0 -Pillow==10.2.0 -pyarrow==14.0.1 -openpyxl==3.1.2 +pandas==2.2.3 +tqdm==4.67.0 +requests==2.32.3 +Pillow==11.0.0 +pyarrow==18.0.0 +openpyxl==3.1.5 pyzbar~=0.1.9 -qrcode~=7.4.2 +qrcode~=8.0 fake-useragent \ No newline at end of file diff --git a/util/LoginUtil.py b/util/LoginUtil.py index 1631e1d..f3094b5 100644 --- a/util/LoginUtil.py +++ b/util/LoginUtil.py @@ -1,5 +1,7 @@ import platform import sys +import os +import subprocess import qrcode import requests @@ -9,15 +11,45 @@ try: from pyzbar.pyzbar import decode except Exception as e: print("无法找到 zbar 共享库。请确保安装了 zbar。") + import_success = False + if platform.system() == "Linux": print("对于基于 RPM 的系统(如 Fedora), 您可以运行以下命令:") print("sudo dnf install -y zbar") elif platform.system() == "Darwin": print("MacOS 安装 zbar 请参考:") print("https://github.com/LibraHp/GetQzonehistory/issues/23#issuecomment-2349269027") + + try: + subprocess.check_call(["brew", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + print("检测到您已安装 Homebrew。是否通过 Homebrew 安装 zbar? (y/n)") + user_input = input().strip().lower() + + if user_input == "y": + # 安装 zbar + subprocess.check_call(["brew", "install", "zbar"]) + + # 创建 lib 目录和符号链接 + if not os.path.exists("lib"): + os.makedirs("lib") + + zbar_lib_path = os.path.join(subprocess.check_output(["brew", "--prefix", "zbar"], text=True).strip(), "lib", "libzbar.dylib") + subprocess.check_call(["ln", "-s", zbar_lib_path, "./lib/libzbar.dylib"]) + print("zbar 安装并配置成功。") + + # 尝试导入 pyzbar + from pyzbar.pyzbar import decode + import_success = True + except FileNotFoundError: + print("未检测到 Homebrew。请先安装 Homebrew 或参考文档手动安装 zbar。") + except subprocess.CalledProcessError: + print("检测 Homebrew 版本时出错,请确保 Homebrew 正常安装。") + except Exception as install_error: + print(f"安装过程中发生错误: {install_error}") + + if not import_success: + print("有关更多安装指南,请参考 zbar 的官方文档或您的发行版文档。") sys.exit(1) - print("有关更多安装指南,请参考 zbar 的官方文档或您的发行版文档。") - sys.exit(1) import time import re