-
Notifications
You must be signed in to change notification settings - Fork 1
/
WeChat_PC.py
87 lines (67 loc) · 2.25 KB
/
WeChat_PC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# !/usr/bin/env python
# -*- encoding: utf-8 -*-
# @File: main.py
# @Author: SWHL
# @Contact: [email protected]
import os
import random
import time
import numpy as np
import pyautogui
import pyperclip
from tqdm import tqdm
from PIL import ImageGrab
from rapidocr import TextSystem
det_model_path = "resources/models/ch_PP-OCRv2_det_infer.onnx"
cls_model_path = "resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx"
rec_model_path = "resources/models/ch_ppocr_mobile_v2.0_rec_infer.onnx"
dict_path = "resources/ppocr_keys_v1.txt"
text_sys = TextSystem(det_model_path,
rec_model_path,
cls_model_path,
dict_path)
def read_txt(txt_path: str) -> list:
with open(txt_path, 'r', encoding='utf-8') as f:
data = list(map(lambda x: x.rstrip('\n'), f))
return data
class WeChat(object):
def __init__(self, wechat_path):
self.wechat_path = wechat_path
self._open_wechat()
self._get_ocr()
def _open_wechat(self):
pyautogui.hotkey('win', 'd')
file = os.popen(self.wechat_path)
file.close()
time.sleep(2)
def _get_ocr(self):
result_boxes = None
dt_boxes, rec_res = text_sys(np.array(ImageGrab.grab()))
for dt_box, rec in zip(dt_boxes, rec_res):
if rec[0].__contains__('搜索'):
result_boxes = dt_box
self.x = np.mean(result_boxes[:, 0])
self.y = np.mean(result_boxes[:, 1])
def send_msg_obj(self, name):
print('点击搜索')
pyautogui.moveTo(self.x, self.y)
pyautogui.click(self.x, self.y)
time.sleep(1)
print('输入姓名')
pyperclip.copy(name)
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
print('点击搜素')
pyautogui.hotkey('enter')
time.sleep(2)
if __name__ == '__main__':
wechat = WeChat(r'"F:\WeChat\WeChat.exe"')
message_list = read_txt('assets/friend_name.txt')
person_list = read_txt('assets/bless.txt')
for one_name in tqdm(person_list):
# 选择人
wechat.send_msg_obj(one_name)
# 生成文案
random_one = random.choice(message_list)
random_one = f'{one_name}\n{random_one}'
wechat.send_msg(random_one)