From f0a9340a51bdf6346164e205de98c3fd18d68066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E=E6=98=8E?= Date: Mon, 6 May 2024 20:03:31 +0800 Subject: [PATCH] version 0.0.7 --- setup.py | 2 +- wxhook/__init__.py | 2 +- wxhook/core.py | 7 ++++--- wxhook/utils.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index e86bf86..e8914bf 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ URL = 'https://github.com/miloira/wxhook' EMAIL = '690126048@qq.com' AUTHOR = 'Msky' REQUIRES_PYTHON = '>=3.8.0' -VERSION = '0.0.6' +VERSION = '0.0.7' # What packages are required for this module to be executed? REQUIRED = [ diff --git a/wxhook/__init__.py b/wxhook/__init__.py index 5ceaa1f..b670716 100644 --- a/wxhook/__init__.py +++ b/wxhook/__init__.py @@ -1,3 +1,3 @@ from .core import Bot -version = "0.0.6" +version = "0.0.7" diff --git a/wxhook/core.py b/wxhook/core.py index 7b7e88d..0a5acfd 100644 --- a/wxhook/core.py +++ b/wxhook/core.py @@ -70,10 +70,11 @@ class Bot: try: code, output = start_wechat_with_inject(self.remote_port) - if code == 1: - raise Exception(output) except Exception: - output = get_pid(self.remote_port) + code, output = get_pid(self.remote_port) + + if code == 1: + raise Exception(output) self.process = psutil.Process(int(output)) diff --git a/wxhook/utils.py b/wxhook/utils.py index e65f57d..5159c6e 100644 --- a/wxhook/utils.py +++ b/wxhook/utils.py @@ -33,9 +33,9 @@ def get_processes(process_name: str) -> typing.List[psutil.Process]: return processes -def get_pid(port: int) -> int: +def get_pid(port: int) -> typing.Tuple[int, int]: output = subprocess.run(f"netstat -ano | findStr \"{port}\"", capture_output=True, text=True, shell=True).stdout - return int(output.split("\n")[0].split("LISTENING")[-1]) + return 0, int(output.split("\n")[0].split("LISTENING")[-1]) def parse_xml(xml: str) -> dict: