Skip to content

Commit 095f74f

Browse files
committed
[feat] add retry for io operate
1 parent ce58a96 commit 095f74f

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.idea
22
__pycache__
33
.DS_Store
4-
venv
4+
venv
5+
build/
6+
dist/
7+
main.spec

main.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import re
44
import time
55
from enum import Enum
6-
from PyQt5.QtWidgets import *
7-
from PyQt5.QtGui import *
6+
from PySide2.QtWidgets import *
7+
from PySide2.QtGui import *
88
from xtool import Ui_MainWindow
99
import pyautogui
1010

1111
if platform.system() == "Windows":
1212
import ctypes
13-
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
13+
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("wxtool")
1414

1515

1616
# 号码状态
@@ -101,6 +101,7 @@ def start_invite(self):
101101
continue
102102
try:
103103
state = self.add_friend(friend_info["phone"])
104+
friend_info["state"] = state
104105
except RuntimeError as e:
105106
QMessageBox.warning(self, "错误", str(e))
106107
return
@@ -132,7 +133,7 @@ def add_friend(phone):
132133
retry = 5
133134
# 查找用户
134135
while retry > 0:
135-
time.sleep(1)
136+
time.sleep(0.5)
136137
retry = retry - 1
137138
search_result = pyautogui.locateCenterOnScreen('./stepPic/search_result.png', confidence=0.9)
138139
if not search_result:
@@ -156,11 +157,23 @@ def add_friend(phone):
156157
else:
157158
raise RuntimeError("未知错误")
158159
pyautogui.click(add)
159-
send = pyautogui.locateCenterOnScreen('./stepPic/send.png', confidence=0.9)
160-
if not send:
161-
raise RuntimeError("未找到发送按钮")
162-
pyautogui.click(send)
163-
time.sleep(1)
160+
send_retry = 5
161+
while send_retry > 0:
162+
time.sleep(0.5)
163+
send_retry = send_retry - 1
164+
send = pyautogui.locateCenterOnScreen('./stepPic/send.png', confidence=0.9)
165+
if send:
166+
pyautogui.click(send)
167+
break
168+
elif send_retry == 0:
169+
raise RuntimeError("未找到发送按钮")
170+
send_result_retry = 5
171+
while send_result_retry > 0:
172+
time.sleep(0.5)
173+
send_result_retry = send_result_retry - 1
174+
send_result = pyautogui.locateCenterOnScreen('./stepPic/send_result.png', confidence=0.9)
175+
if send_result:
176+
break
164177
return PhoneState.Succeed
165178

166179
def main():

requirements.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
pyqt5
2-
pyqt5-tools
31
PySide2
4-
PyQt5-stubs
52
PyAutoGUI
6-
pyperclip
73
opencv-python

stepPic/send_result.png

621 Bytes
Loading

xtool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# run again. Do not edit this file unless you know what you are doing.
99

1010

11-
from PyQt5 import QtCore, QtGui, QtWidgets
11+
from PySide2 import QtCore, QtGui, QtWidgets
1212

1313

1414
class Ui_MainWindow(object):

0 commit comments

Comments
 (0)