Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from walklty/dev
Browse files Browse the repository at this point in the history
结构重写,使用class
log逻辑和方式重写
更多的图像判断
增加每日监察密令领取
  • Loading branch information
DabengBa authored Sep 25, 2023
2 parents 4e1b2fe + 8f77e2a commit b38fddd
Show file tree
Hide file tree
Showing 32 changed files with 881 additions and 469 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ __pycache__/wqmt.cpython-311.pyc
*.pyc
*.pyc
*.pyc
main.exe
main.spec
*.txt
main.spec
main.spec
main.spec
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
![img](https://github.com/walklty/wqmt_assistant/blob/dev/Target/Snipaste_2023-09-09_05-17-32.png?raw=true)


# 主要更新内容

📅202309xx 我跟ChatGPT说,你看人家代码都有个class什么的,你也这样给我改改。

改了一些寻找图片的循环逻辑,增加了一些图像识别步骤。

重写了log的逻辑,固定了一个滚动窗口输出内容,重点内容会有单独的提示。

增加了监察密令的每日领取

📅20230909 增加了肉鸽刷界石的步骤。进去退出来竟然有20界石……个人感觉有点bug

请在游戏主界面启动。请先通关一次。
Expand Down
File renamed without changes
Binary file added Target/wqmt/caigouban02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/fuben_xiuhe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added Target/wqmt/supervision01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/supervision08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Target/wqmt/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ remote_dir: /sdcard/screenshot.png # 部分模拟器存储截图的位置不同,
device_name2: 127.0.0.1:16384

# 程序自动配置, 勿动
curr_dir: C:\Software\DEV\wqmt_assistant

saved_selections:
- 管理局
- 监察密令
Empty file removed log/oc.txt
Empty file.
30 changes: 17 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from utils.functions import *
import wqmt as wq
from pywebio.input import actions as pw_actions
import pywebio as pw
import utils.log as log
import utils.adb as adb

if __name__ == '__main__':
adb_connect()
log.logit("请提前在Config.yaml中配置好mumu的ip地址和端口")
log.logit("建议按照12小时间隔,早晚各一次。晚上执行的时候请在17点之后,以便领取体力")
if __name__ == "__main__":
adb.connect()
pw.output.put_text("请提前在Config.yaml中配置好mumu的ip地址和端口")
pw.output.put_text("建议按照12小时间隔,早晚各一次。晚上执行的时候请在17点之后,以便领取体力")

options = ['早一次', '晚一次', '自选', '单刷肉鸽']
log.logit("打开options界面")
selected_options = pw_actions("嗯……", options)
options = ["早一次", "晚一次", "自选", "单刷肉鸽"]
selected_options = pw.input.actions("嗯……", options)
if cfg.log_switch == "close":
pw.output.put_text(f"config.yaml中已经关闭日志输出,之后本窗口可以关闭")
if "早一次" in selected_options:
wq.morning()
log.logit("完成所有任务")
log.logit(f"完成所有任务").text()
if "晚一次" in selected_options:
wq.night()
log.logit("完成所有任务")
log.logit(f"完成所有任务").text()
if "自选" in selected_options:
log.logit("打开自选界面")
log.logit(f"打开自选界面").text()
agree = wq.select_jobs()
if "启动" in agree:
wq.starttohome()
Expand All @@ -36,13 +38,15 @@
wq.Bureau()
if "好友" in agree:
wq.friends()
if "监察密令" in agree:
wq.supervision()
if "副本-锈河记忆" in agree:
wq.raidriver()
if "副本-11-6" in agree:
wq.raid11()
if "副本-深井" in agree:
wq.raiddark()
log.logit("完成所有任务")
if '单刷肉鸽' in selected_options:
log.logit("完成所有任务").text()
if "单刷肉鸽" in selected_options:
wq.starttohome()
wq.rouge()
16 changes: 5 additions & 11 deletions main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,21 @@ pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main',
)
8 changes: 8 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from utils.functions import *
import wqmt as wq
import utils.log as log
import utils.adb as adb
import time as time
import pywebio as pw

log.logit().img()
63 changes: 40 additions & 23 deletions utils/PPOCR_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# https://github.com/hiroi-sora/PaddleOCR-json

import os
import socket # 套接字
import socket # 套接字
import subprocess # 进程,管道
from json import loads as jsonLoads, dumps as jsonDumps
from sys import platform as sysPlatform # popen静默模式
from base64 import b64encode # base64 编码
from base64 import b64encode # base64 编码


class PPOCR_pipe:
Expand All @@ -30,20 +30,25 @@ def __init__(self, exePath: str, argument: dict = None):
startupinfo = None
if "win32" in str(sysPlatform).lower():
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
startupinfo.dwFlags = (
subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
)
startupinfo.wShowWindow = subprocess.SW_HIDE
self.ret = subprocess.Popen( # 打开管道
exePath, cwd=cwd,
exePath,
cwd=cwd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, # 丢弃stderr的内容
startupinfo=startupinfo # 开启静默模式
startupinfo=startupinfo, # 开启静默模式
)
# 启动子进程
while True:
if not self.ret.poll() == None: # 子进程已退出,初始化失败
raise Exception(f"OCR init fail.")
initStr = self.ret.stdout.readline().decode("utf-8", errors="ignore")
initStr = self.ret.stdout.readline().decode(
"utf-8", errors="ignore"
)
if "OCR init completed." in initStr: # 初始化成功
break

Expand All @@ -55,7 +60,7 @@ def runDict(self, writeDict: dict):
if not self.ret.poll() == None:
return {"code": 901, "data": f"子进程已崩溃。"}
# 输入信息
writeStr = jsonDumps(writeDict, ensure_ascii=True, indent=None)+"\n"
writeStr = jsonDumps(writeDict, ensure_ascii=True, indent=None) + "\n"
try:
self.ret.stdin.write(writeStr.encode("utf-8"))
self.ret.stdin.flush()
Expand All @@ -69,7 +74,10 @@ def runDict(self, writeDict: dict):
try:
return jsonLoads(getStr)
except Exception as e:
return {"code": 904, "data": f"识别器输出值反序列化JSON失败。异常信息:[{e}]。原始内容:[{getStr}]"}
return {
"code": 904,
"data": f"识别器输出值反序列化JSON失败。异常信息:[{e}]。原始内容:[{getStr}]",
}

def run(self, imgPath: str):
"""对一张本地图片进行文字识别。\n
Expand All @@ -94,7 +102,7 @@ def runBytes(self, imageBytes):
"""对一张图片的字节流信息进行文字识别。\n
`imageBytes`: 图片字节流。\n
`return`: {"code": 识别码, "data": 内容列表或错误信息字符串}\n"""
imageBase64 = b64encode(imageBytes).decode('utf-8')
imageBase64 = b64encode(imageBytes).decode("utf-8")
return self.runBase64(imageBase64)

def exit(self):
Expand All @@ -110,8 +118,10 @@ def printResult(res: dict):
if res["code"] == 100:
index = 1
for line in res["data"]:
print(f"{index}-置信度:{round(line['score'], 2)},文本:{line['text']}")
index+=1
print(
f"{index}-置信度:{round(line['score'], 2)},文本:{line['text']}"
)
index += 1
elif res["code"] == 100:
print("图片中未识别出文字。")
else:
Expand All @@ -120,6 +130,7 @@ def printResult(res: dict):
def __del__(self):
self.exit()


class PPOCR_socket(PPOCR_pipe):
"""调用OCR(套接字模式)"""

Expand All @@ -131,18 +142,18 @@ def __init__(self, exePath: str, argument: dict = None):
# 处理参数
if not argument:
argument = {}
argument["port"] = 0 # 随机端口号
argument["addr"] = "loopback" # 本地环回地址
super().__init__(exePath, argument) # 父类构造函数
argument["port"] = 0 # 随机端口号
argument["addr"] = "loopback" # 本地环回地址
super().__init__(exePath, argument) # 父类构造函数
# 再获取一行输出,检查是否成功启动服务器
initStr = self.ret.stdout.readline().decode("utf-8", errors="ignore")
if not self.ret.poll() == None: # 子进程已退出,初始化失败
raise Exception(f"Socket init fail.")
if "Socket init completed. " in initStr: # 初始化成功
splits = initStr.split(":")
self.ip = splits[0].split("Socket init completed. ")[1]
self.port = int(splits[1]) # 提取端口号
self.ret.stdout.close() # 关闭管道重定向,防止缓冲区填满导致堵塞
self.port = int(splits[1]) # 提取端口号
self.ret.stdout.close() # 关闭管道重定向,防止缓冲区填满导致堵塞
print(f"套接字服务器初始化成功。{self.ip}:{self.port}")
return
# 异常
Expand All @@ -157,34 +168,38 @@ def runDict(self, writeDict: dict):
if not self.ret.poll() == None:
return {"code": 901, "data": f"子进程已崩溃。"}
# 通信
writeStr = jsonDumps(writeDict, ensure_ascii=True, indent=None)+"\n"
writeStr = jsonDumps(writeDict, ensure_ascii=True, indent=None) + "\n"
try:
# 创建TCP连接
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientSocket.connect((self.ip, self.port))
# 发送数据
clientSocket.sendall(writeStr.encode())
# 接收数据
resData = b''
resData = b""
while True:
chunk = clientSocket.recv(1024)
if not chunk:
break
resData += chunk
getStr = resData.decode()
except ConnectionRefusedError:
return {"code":902, "data": "连接被拒绝"}
return {"code": 902, "data": "连接被拒绝"}
except TimeoutError:
return {"code":903, "data": "连接超时"}
return {"code": 903, "data": "连接超时"}
except Exception as e:
return {"code":904, "data": f"网络错误:{e}"}
return {"code": 904, "data": f"网络错误:{e}"}
finally:
clientSocket.close() # 关闭连接
# 反序列输出信息
try:
return jsonLoads(getStr)
except Exception as e:
return {"code": 905, "data": f"识别器输出值反序列化JSON失败。异常信息:[{e}]。原始内容:[{getStr}]"}
return {
"code": 905,
"data": f"识别器输出值反序列化JSON失败。异常信息:[{e}]。原始内容:[{getStr}]",
}


def GetOcrApi(exePath: str, argument: dict = None, ipcMode: str = "pipe"):
"""获取识别器API对象。\n
Expand All @@ -197,4 +212,6 @@ def GetOcrApi(exePath: str, argument: dict = None, ipcMode: str = "pipe"):
elif ipcMode == "pipe":
return PPOCR_pipe(exePath, argument)
else:
raise Exception(f'ipcMode可选值为 套接字模式"socket" 或 管道模式"pipe" ,不允许{ipcMode}。')
raise Exception(
f'ipcMode可选值为 套接字模式"socket" 或 管道模式"pipe" ,不允许{ipcMode}。'
)
Loading

0 comments on commit b38fddd

Please sign in to comment.