pywechat127 1.5.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pywechat127-1.5.8/LICENSE.txt +201 -0
- pywechat127-1.5.8/PKG-INFO +124 -0
- pywechat127-1.5.8/README.md +105 -0
- pywechat127-1.5.8/pywechat/Clock.py +88 -0
- pywechat127-1.5.8/pywechat/Errors.py +75 -0
- pywechat127-1.5.8/pywechat/Uielements.py +81 -0
- pywechat127-1.5.8/pywechat/Warnings.py +13 -0
- pywechat127-1.5.8/pywechat/WechatAuto.py +7866 -0
- pywechat127-1.5.8/pywechat/WechatTools.py +1973 -0
- pywechat127-1.5.8/pywechat/WinSettings.py +335 -0
- pywechat127-1.5.8/pywechat/__init__.py +43 -0
- pywechat127-1.5.8/pywechat127.egg-info/PKG-INFO +124 -0
- pywechat127-1.5.8/pywechat127.egg-info/SOURCES.txt +17 -0
- pywechat127-1.5.8/pywechat127.egg-info/dependency_links.txt +1 -0
- pywechat127-1.5.8/pywechat127.egg-info/requires.txt +7 -0
- pywechat127-1.5.8/pywechat127.egg-info/top_level.txt +1 -0
- pywechat127-1.5.8/setup.cfg +7 -0
- pywechat127-1.5.8/setup.py +16 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [pywechat127] [Hello-Mr-Crab]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pywechat127
|
|
3
|
+
Version: 1.5.8
|
|
4
|
+
Summary: A Powerful Windows-PC-Wechat automation Tool
|
|
5
|
+
Home-page: https://github.com/Hello-Mr-Crab/pywechat
|
|
6
|
+
Author: Hello-Mr-Crab
|
|
7
|
+
Author-email: 3083256475@qq.com
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Keywords: rpa,windows,wechat,automation
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE.txt
|
|
12
|
+
Requires-Dist: PyAutoGUI>=0.9.54
|
|
13
|
+
Requires-Dist: pycaw>=20240210
|
|
14
|
+
Requires-Dist: pywin32>=308
|
|
15
|
+
Requires-Dist: pywin32-ctypes>=0.2.2
|
|
16
|
+
Requires-Dist: pywinauto>=0.6.8
|
|
17
|
+
Requires-Dist: psutil>=5.9.6
|
|
18
|
+
Requires-Dist: pillow>=11.1.0
|
|
19
|
+
|
|
20
|
+
# pywechat🥇
|
|
21
|
+

|
|
22
|
+
## 🍬🍬pywechat是一款基于pywinauto实现的Windows系统下PC微信自动化的Python项目。它可以帮助用户实现微信的一系列自动化操作,包括发送消息、发送文件、自动回复以及针对微信好友的所有操作,针对微信群聊的所有操作,支持单线程多个任务轮流进行,完全模拟真人操作微信。
|
|
23
|
+
|
|
24
|
+
### 微信版本:3.9.12.17
|
|
25
|
+
### 操作系统:🪟windows 10 🪟windows 11
|
|
26
|
+
### python版本🐍:3.x
|
|
27
|
+
### pywechat项目结构:
|
|
28
|
+

|
|
29
|
+
<br>
|
|
30
|
+
|
|
31
|
+
## 该项目内的函数与方法名称与PC微信英文版各界面与功能英文翻译一致。其中pywechat的open_wechat函数无论微信是否打开,是否登录(需先前登录过,手机端勾选自动登录)均可正常打开微信,你只需要将微信WeChat.exe文件地址传入pywechat各个函数,或添加到windows用户环境变量中即可开启微信自动化之旅。🗺️🗺️
|
|
32
|
+
### 注:pywechat最新版本已内置自动添加WeChat.exe为windows用户环境变量的方法。
|
|
33
|
+
这里强烈建议将微信Wechat.exe文件添加到windows系统环境变量中,因为pywechat默认使用windows环境变量中的Wechat.exe路径启动微信,此时调用其中的每个方法与函数无需传入wechat_path参数即可自动化操作微信。
|
|
34
|
+
|
|
35
|
+
<br>
|
|
36
|
+
|
|
37
|
+
### 获取方法:
|
|
38
|
+
```
|
|
39
|
+
pip install pywechat127==1.5.0
|
|
40
|
+
```
|
|
41
|
+
<br>
|
|
42
|
+
|
|
43
|
+
### 添加微信至windows用户环境变量:
|
|
44
|
+
#### pywechat已内置自动添加微信至用户环境变量的方法,运行下列代码即可自动添加微信路径至windows用户变量 :
|
|
45
|
+
```
|
|
46
|
+
from pywechat.WechatTools import Tools
|
|
47
|
+
Tools.set_wechat_as_environ_path()
|
|
48
|
+
```
|
|
49
|
+
#### 效果演示:
|
|
50
|
+

|
|
51
|
+
<br>
|
|
52
|
+
|
|
53
|
+
### WechatTools🌪️🌪️
|
|
54
|
+
#### 模块包括:
|
|
55
|
+
#### Tools:关于PC微信的一些工具,包括3个关于PC微信程序的方法和10个打开PC微信内各个界面的open系列方法。
|
|
56
|
+
#### API:打开指定微信小程序,指定公众号,打开视频号的功能,若有其他开发者想自动化操作上述程序可调用此API。
|
|
57
|
+
#### 函数:该模块内所有函数为上述模块内的所有方法。
|
|
58
|
+
<br>
|
|
59
|
+
|
|
60
|
+
### WechatAuto🛏️🛏️
|
|
61
|
+
#### 模块包括:
|
|
62
|
+
##### Messages: 5种类型的发送消息方法,包括:单人单条,单人多条,多人单条,多人多条,转发消息:多人同一条。
|
|
63
|
+
##### Files: 5种类型的发送文件方法,包括:单人单个,单人多个,多人单个,多人多个,转发文件:多人同一个。发送多个文件时,你只需将所有文件放入文件夹内,将文件夹路径传入即可。
|
|
64
|
+
##### FriendSettings: 涵盖了PC微信针对某个好友的全部操作的方法。
|
|
65
|
+
##### GroupSettings: 涵盖了PC微信针对某个群聊的全部操作的方法。
|
|
66
|
+
##### Contacts: 获取3种类型通讯录好友的备注与昵称包括:微信好友,企业号微信,群聊名称与人数,数据返回格式为json。
|
|
67
|
+
##### Call: 给某个好友打视频或语音电话。
|
|
68
|
+
##### AutoReply:自动接应微信视频或语音电话。
|
|
69
|
+
#### 函数:该模块内所有函数为上述模块内的所有方法。
|
|
70
|
+
<br>
|
|
71
|
+
|
|
72
|
+
### WinSettings🔹🔹
|
|
73
|
+
#### 模块包括:
|
|
74
|
+
#### Systemsettings:该模块中提供了7个修改windows系统设置和3个判断文件类型的方法。
|
|
75
|
+
#### 函数:该模块内所有函数为上述模块内的所有方法。
|
|
76
|
+
<br>
|
|
77
|
+
|
|
78
|
+
### 使用示例:
|
|
79
|
+
#### (注意,微信WeChat.exe路径已添加至windows系统环境变量,故以下方法或函数无需传入wechat_path这一参数)
|
|
80
|
+
#### 给某个好友发送多条信息:
|
|
81
|
+
```
|
|
82
|
+
from pywechat.WechatAuto import Messages
|
|
83
|
+
Messages.send_messages_to_friend(friend="文件传输助手",messages=['你好','我正在使用pywechat操控微信给你发消息','收到请回复'])
|
|
84
|
+
```
|
|
85
|
+
##### 或者
|
|
86
|
+
```
|
|
87
|
+
import pywechat.WechatAuto as wechat
|
|
88
|
+
wechat.send_messages_to_friend(friend="文件传输助手",messages=['你好','我正在使用pywechat操控微信给你发消息','收到请回复'])
|
|
89
|
+
```
|
|
90
|
+
<br>
|
|
91
|
+
|
|
92
|
+
#### 自动接听语音视频电话:
|
|
93
|
+
```
|
|
94
|
+
from pywechat.WechatAuto import AutoReply
|
|
95
|
+
AutoReply.auto_answer_call(broadcast_content='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',message='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',duration='1h',times=1)
|
|
96
|
+
```
|
|
97
|
+
##### 或者
|
|
98
|
+
```
|
|
99
|
+
import pywechat.WechatAuto as wechat
|
|
100
|
+
wechat.auto_answer_call(broadcast_content='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',message='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',duration='1h',times=1)
|
|
101
|
+
```
|
|
102
|
+
### 多任务使用示例
|
|
103
|
+
#### 注意,微信不支持多线程,只支持单线程多任务轮流执行,pywechat也支持单线程多任务轮流执行,在运行多个实例时尽量请将所有函数与方法内的close_wechat参数设为False(默认为True)
|
|
104
|
+
#### 这样只需要打开一次微信,多个任务便可以共享资源,更加高效,否则,每个实例在运行时都会重启一次微信,较为低效。
|
|
105
|
+
<br>
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
from pywechat.WechatAuto import Messages,Files
|
|
109
|
+
Messages.send_messages_to_friend(friend='好友1',messages=['在测试','ok'],close_wechat=False)
|
|
110
|
+
Files.send_files_to_friend(friend='文件传输助手',folder_path=r"E:\OneDrive\Desktop\测试专用",with_messages=True,messages_first=True,messages=['在测试文件消息一起发,你应该先看到这条消息,后看到文件'],close_wechat=True)
|
|
111
|
+
```
|
|
112
|
+
#### 效果演示:
|
|
113
|
+

|
|
114
|
+
|
|
115
|
+
##### AI自动回复代码:
|
|
116
|
+
<br>
|
|
117
|
+
|
|
118
|
+

|
|
119
|
+
|
|
120
|
+
<br>
|
|
121
|
+
|
|
122
|
+
##### 自动回复效果:
|
|
123
|
+
|
|
124
|
+

|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# pywechat🥇
|
|
2
|
+

|
|
3
|
+
## 🍬🍬pywechat是一款基于pywinauto实现的Windows系统下PC微信自动化的Python项目。它可以帮助用户实现微信的一系列自动化操作,包括发送消息、发送文件、自动回复以及针对微信好友的所有操作,针对微信群聊的所有操作,支持单线程多个任务轮流进行,完全模拟真人操作微信。
|
|
4
|
+
|
|
5
|
+
### 微信版本:3.9.12.17
|
|
6
|
+
### 操作系统:🪟windows 10 🪟windows 11
|
|
7
|
+
### python版本🐍:3.x
|
|
8
|
+
### pywechat项目结构:
|
|
9
|
+

|
|
10
|
+
<br>
|
|
11
|
+
|
|
12
|
+
## 该项目内的函数与方法名称与PC微信英文版各界面与功能英文翻译一致。其中pywechat的open_wechat函数无论微信是否打开,是否登录(需先前登录过,手机端勾选自动登录)均可正常打开微信,你只需要将微信WeChat.exe文件地址传入pywechat各个函数,或添加到windows用户环境变量中即可开启微信自动化之旅。🗺️🗺️
|
|
13
|
+
### 注:pywechat最新版本已内置自动添加WeChat.exe为windows用户环境变量的方法。
|
|
14
|
+
这里强烈建议将微信Wechat.exe文件添加到windows系统环境变量中,因为pywechat默认使用windows环境变量中的Wechat.exe路径启动微信,此时调用其中的每个方法与函数无需传入wechat_path参数即可自动化操作微信。
|
|
15
|
+
|
|
16
|
+
<br>
|
|
17
|
+
|
|
18
|
+
### 获取方法:
|
|
19
|
+
```
|
|
20
|
+
pip install pywechat127==1.5.0
|
|
21
|
+
```
|
|
22
|
+
<br>
|
|
23
|
+
|
|
24
|
+
### 添加微信至windows用户环境变量:
|
|
25
|
+
#### pywechat已内置自动添加微信至用户环境变量的方法,运行下列代码即可自动添加微信路径至windows用户变量 :
|
|
26
|
+
```
|
|
27
|
+
from pywechat.WechatTools import Tools
|
|
28
|
+
Tools.set_wechat_as_environ_path()
|
|
29
|
+
```
|
|
30
|
+
#### 效果演示:
|
|
31
|
+

|
|
32
|
+
<br>
|
|
33
|
+
|
|
34
|
+
### WechatTools🌪️🌪️
|
|
35
|
+
#### 模块包括:
|
|
36
|
+
#### Tools:关于PC微信的一些工具,包括3个关于PC微信程序的方法和10个打开PC微信内各个界面的open系列方法。
|
|
37
|
+
#### API:打开指定微信小程序,指定公众号,打开视频号的功能,若有其他开发者想自动化操作上述程序可调用此API。
|
|
38
|
+
#### 函数:该模块内所有函数为上述模块内的所有方法。
|
|
39
|
+
<br>
|
|
40
|
+
|
|
41
|
+
### WechatAuto🛏️🛏️
|
|
42
|
+
#### 模块包括:
|
|
43
|
+
##### Messages: 5种类型的发送消息方法,包括:单人单条,单人多条,多人单条,多人多条,转发消息:多人同一条。
|
|
44
|
+
##### Files: 5种类型的发送文件方法,包括:单人单个,单人多个,多人单个,多人多个,转发文件:多人同一个。发送多个文件时,你只需将所有文件放入文件夹内,将文件夹路径传入即可。
|
|
45
|
+
##### FriendSettings: 涵盖了PC微信针对某个好友的全部操作的方法。
|
|
46
|
+
##### GroupSettings: 涵盖了PC微信针对某个群聊的全部操作的方法。
|
|
47
|
+
##### Contacts: 获取3种类型通讯录好友的备注与昵称包括:微信好友,企业号微信,群聊名称与人数,数据返回格式为json。
|
|
48
|
+
##### Call: 给某个好友打视频或语音电话。
|
|
49
|
+
##### AutoReply:自动接应微信视频或语音电话。
|
|
50
|
+
#### 函数:该模块内所有函数为上述模块内的所有方法。
|
|
51
|
+
<br>
|
|
52
|
+
|
|
53
|
+
### WinSettings🔹🔹
|
|
54
|
+
#### 模块包括:
|
|
55
|
+
#### Systemsettings:该模块中提供了7个修改windows系统设置和3个判断文件类型的方法。
|
|
56
|
+
#### 函数:该模块内所有函数为上述模块内的所有方法。
|
|
57
|
+
<br>
|
|
58
|
+
|
|
59
|
+
### 使用示例:
|
|
60
|
+
#### (注意,微信WeChat.exe路径已添加至windows系统环境变量,故以下方法或函数无需传入wechat_path这一参数)
|
|
61
|
+
#### 给某个好友发送多条信息:
|
|
62
|
+
```
|
|
63
|
+
from pywechat.WechatAuto import Messages
|
|
64
|
+
Messages.send_messages_to_friend(friend="文件传输助手",messages=['你好','我正在使用pywechat操控微信给你发消息','收到请回复'])
|
|
65
|
+
```
|
|
66
|
+
##### 或者
|
|
67
|
+
```
|
|
68
|
+
import pywechat.WechatAuto as wechat
|
|
69
|
+
wechat.send_messages_to_friend(friend="文件传输助手",messages=['你好','我正在使用pywechat操控微信给你发消息','收到请回复'])
|
|
70
|
+
```
|
|
71
|
+
<br>
|
|
72
|
+
|
|
73
|
+
#### 自动接听语音视频电话:
|
|
74
|
+
```
|
|
75
|
+
from pywechat.WechatAuto import AutoReply
|
|
76
|
+
AutoReply.auto_answer_call(broadcast_content='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',message='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',duration='1h',times=1)
|
|
77
|
+
```
|
|
78
|
+
##### 或者
|
|
79
|
+
```
|
|
80
|
+
import pywechat.WechatAuto as wechat
|
|
81
|
+
wechat.auto_answer_call(broadcast_content='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',message='您好,我目前不在线我的PC微信正在由我的微信机器人控制请稍后再试',duration='1h',times=1)
|
|
82
|
+
```
|
|
83
|
+
### 多任务使用示例
|
|
84
|
+
#### 注意,微信不支持多线程,只支持单线程多任务轮流执行,pywechat也支持单线程多任务轮流执行,在运行多个实例时尽量请将所有函数与方法内的close_wechat参数设为False(默认为True)
|
|
85
|
+
#### 这样只需要打开一次微信,多个任务便可以共享资源,更加高效,否则,每个实例在运行时都会重启一次微信,较为低效。
|
|
86
|
+
<br>
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
from pywechat.WechatAuto import Messages,Files
|
|
90
|
+
Messages.send_messages_to_friend(friend='好友1',messages=['在测试','ok'],close_wechat=False)
|
|
91
|
+
Files.send_files_to_friend(friend='文件传输助手',folder_path=r"E:\OneDrive\Desktop\测试专用",with_messages=True,messages_first=True,messages=['在测试文件消息一起发,你应该先看到这条消息,后看到文件'],close_wechat=True)
|
|
92
|
+
```
|
|
93
|
+
#### 效果演示:
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+
##### AI自动回复代码:
|
|
97
|
+
<br>
|
|
98
|
+
|
|
99
|
+

|
|
100
|
+
|
|
101
|
+
<br>
|
|
102
|
+
|
|
103
|
+
##### 自动回复效果:
|
|
104
|
+
|
|
105
|
+

|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
'''
|
|
3
|
+
定时模块schedule:可以按照当天指定时刻或一段时间后运行指定函数或方法\n
|
|
4
|
+
使用方法:\n
|
|
5
|
+
在指定的一段时间后执行\n
|
|
6
|
+
from pywechat127.clock import schedule\n
|
|
7
|
+
schedule(funcs=[func1,func2],parameters=[{func1的参数字典},{func2的参数字典},waitPeriods=['20s','20min']]).execute()
|
|
8
|
+
在指定的一段时刻执行\n
|
|
9
|
+
from pywechat127.clock import schedule\n
|
|
10
|
+
schedule(funcs=[func1,func2],parameters=[{func1的参数字典},{func2的参数字典},Time=['08:31:14','08:45']]).execute()
|
|
11
|
+
注:时刻可以精确到秒,若某个函数无需任何参数,那你在传入其对印的参数字典时,传入一个空字典即可\n
|
|
12
|
+
若给定的时间戳与当前时间戳之差为负数,定时任务将会立即执行\n
|
|
13
|
+
'''
|
|
14
|
+
import re
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
import asyncio
|
|
17
|
+
from pywechat.WinSettings import Systemsettings
|
|
18
|
+
from pywechat.WechatTools import match_duration
|
|
19
|
+
class schedule:#创建定时任务
|
|
20
|
+
'''
|
|
21
|
+
funcs:所有需要定时执行的函数名列表,注意函数名的类型为函数\n
|
|
22
|
+
不是类型为字符串的函数的名字!\n
|
|
23
|
+
parameters:所有需要定时执行的函数的参数\n
|
|
24
|
+
Times:各个函数定时执行的时间点,Times=['08:31','08:45:54']可精确到秒\n
|
|
25
|
+
waitPeriod:各个函数在指定的一段时间执行的等待时长,waitPeriod=['20s','1h']分别在20s后和1h后执行两个函数、\n
|
|
26
|
+
比如:有两个函数分别为,test1(num:int,string:str),test2(num:int,string:str)\n
|
|
27
|
+
那么传入funcs和parameters时应为:funcs=[test1,test2]\n
|
|
28
|
+
parameters=[{'num':2,'string':'test1'},{{'num':3,'string':'test2'}}]\n
|
|
29
|
+
这个类通过构建协程池来创建定时任务\n
|
|
30
|
+
'''
|
|
31
|
+
def __init__(self,funcs:list,parameters:list[dict],Times:list[str]=[],waitPeriods:list[str]=[]):
|
|
32
|
+
self.Times=Times#指定时间点,'08:31','08:45:54'可精确到秒
|
|
33
|
+
self.waitPeriods=waitPeriods#指定时长,20s,1min,1h
|
|
34
|
+
self.funcs=funcs#所有需要定时执行的函数名
|
|
35
|
+
self.parameters=parameters##所有需要定时执行的函数的参数[{},{}],
|
|
36
|
+
|
|
37
|
+
def calculate_time_difference(self,target_time_string):
|
|
38
|
+
colons=re.findall(r':',target_time_string)
|
|
39
|
+
current_time = datetime.now()
|
|
40
|
+
target_date = current_time.date() # 获取当前日期
|
|
41
|
+
if len(colons)==2:
|
|
42
|
+
target_time_format="%H:%M:%S"
|
|
43
|
+
elif len(colons)==1:
|
|
44
|
+
target_time_format="%H:%M"
|
|
45
|
+
else:
|
|
46
|
+
raise ValueError('输入的时间戳有误!请重新输入!')
|
|
47
|
+
target_time = datetime.combine(target_date, datetime.strptime(target_time_string, target_time_format).time())
|
|
48
|
+
# 计算时间差
|
|
49
|
+
time_difference = target_time - current_time
|
|
50
|
+
hours_difference = time_difference.seconds // 3600 # 整除3600得到小时数
|
|
51
|
+
minutes_remainder = time_difference.seconds % 3600 # 求余得到剩余的秒数,再转换为分钟
|
|
52
|
+
minutes_difference = minutes_remainder // 60 # 整除60得到分钟数
|
|
53
|
+
seconds_difference = minutes_remainder % 60 # 再次求余得到秒数
|
|
54
|
+
print(f"时间差:{hours_difference}小时 {minutes_difference}分钟 {seconds_difference}秒")
|
|
55
|
+
time_difference=time_difference.total_seconds()
|
|
56
|
+
return time_difference
|
|
57
|
+
|
|
58
|
+
async def async_task(self,func,parameter,Time:str=None,waitPeriod:str=None):
|
|
59
|
+
if Time:
|
|
60
|
+
print(f"函数{func.__name__}将会在{Time}时执行")
|
|
61
|
+
await asyncio.sleep(self.calculate_time_difference(Time))
|
|
62
|
+
result=func(**parameter)
|
|
63
|
+
return result
|
|
64
|
+
if waitPeriod:
|
|
65
|
+
print(f"函数{func.__name__}将会在{waitPeriod}后执行")
|
|
66
|
+
waitPeriod=match_duration(waitPeriod)
|
|
67
|
+
await asyncio.sleep(waitPeriod)
|
|
68
|
+
result=func(**parameter)
|
|
69
|
+
return result
|
|
70
|
+
async def main(self):
|
|
71
|
+
#构建协程池实现异步定时任务
|
|
72
|
+
self.tasks=[]
|
|
73
|
+
if self.waitPeriods:
|
|
74
|
+
for func,parameter,waitPeriod in zip(self.funcs,self.parameters,self.waitPeriods):
|
|
75
|
+
self.tasks.append(self.async_task(func,parameter,waitPeriod=waitPeriod))
|
|
76
|
+
results=await asyncio.gather(*self.tasks)
|
|
77
|
+
return results
|
|
78
|
+
if self.Times:
|
|
79
|
+
for func,parameter,time in zip(self.funcs,self.parameters,self.Times):
|
|
80
|
+
self.tasks.append(self.async_task(func,parameter,Time=time))
|
|
81
|
+
results=await asyncio.gather(*self.tasks)
|
|
82
|
+
return results
|
|
83
|
+
def execute(self):
|
|
84
|
+
#运行所有任务
|
|
85
|
+
Systemsettings.open_listening_mode()
|
|
86
|
+
results=asyncio.run(self.main())
|
|
87
|
+
Systemsettings.close_listening_mode()
|
|
88
|
+
return results
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'''各种可能产生的错误'''
|
|
2
|
+
class PathNotFoundError(Exception):
|
|
3
|
+
pass
|
|
4
|
+
class WeChatNotStartError(Exception):
|
|
5
|
+
pass
|
|
6
|
+
class NetWorkNotConnectError(Exception):
|
|
7
|
+
pass
|
|
8
|
+
class ScanCodeToLogInError(Exception):
|
|
9
|
+
pass
|
|
10
|
+
class TimeNotCorrectError(Exception):
|
|
11
|
+
pass
|
|
12
|
+
class HaveBeenPinnedError(Exception):
|
|
13
|
+
pass
|
|
14
|
+
class HaveBeenUnpinnedError(Exception):
|
|
15
|
+
pass
|
|
16
|
+
class NoSuchFriendError(Exception):
|
|
17
|
+
pass
|
|
18
|
+
class HaveBeenMutedError(Exception):
|
|
19
|
+
pass
|
|
20
|
+
class HaveBeenStickiedError(Exception):
|
|
21
|
+
pass
|
|
22
|
+
class HaveBeenUnmutedError(Exception):
|
|
23
|
+
pass
|
|
24
|
+
class HaveBeenUnstickiedError(Exception):
|
|
25
|
+
pass
|
|
26
|
+
class HaveBeenStaredError(Exception):
|
|
27
|
+
pass
|
|
28
|
+
class HaveBeenUnstaredError(Exception):
|
|
29
|
+
pass
|
|
30
|
+
class HaveBeenInBlackListError(Exception):
|
|
31
|
+
pass
|
|
32
|
+
class HaveBeenOutofBlackListError(Exception):
|
|
33
|
+
pass
|
|
34
|
+
class HaveBeenSetChatonlyError(Exception):
|
|
35
|
+
pass
|
|
36
|
+
class HaveBeenSetUnseentohimError(Exception):
|
|
37
|
+
pass
|
|
38
|
+
class HaveBeenSetDontseehimError(Exception):
|
|
39
|
+
pass
|
|
40
|
+
class PrivacytNotCorrectError(Exception):
|
|
41
|
+
pass
|
|
42
|
+
class NoWechat_number_or_Phone_numberError(Exception):
|
|
43
|
+
pass
|
|
44
|
+
class EmptyFileError(Exception):
|
|
45
|
+
pass
|
|
46
|
+
class EmptyFolderError(Exception):
|
|
47
|
+
pass
|
|
48
|
+
class NotFileError(Exception):
|
|
49
|
+
pass
|
|
50
|
+
class NotFolderError(Exception):
|
|
51
|
+
pass
|
|
52
|
+
class CantCreateGroupError(Exception):
|
|
53
|
+
pass
|
|
54
|
+
class NoPermissionError(Exception):
|
|
55
|
+
pass
|
|
56
|
+
class SameNameError(Exception):
|
|
57
|
+
pass
|
|
58
|
+
class AlreadyOpenError(Exception):
|
|
59
|
+
pass
|
|
60
|
+
class AlreadyCloseError(Exception):
|
|
61
|
+
pass
|
|
62
|
+
class AlreadyInContactsError(Exception):
|
|
63
|
+
pass
|
|
64
|
+
class EmptyNoteError(Exception):
|
|
65
|
+
pass
|
|
66
|
+
class NoChatHistoryError(Exception):
|
|
67
|
+
pass
|
|
68
|
+
class HaveBeenSetError(Exception):
|
|
69
|
+
pass
|
|
70
|
+
class NoResultsError(Exception):
|
|
71
|
+
pass
|
|
72
|
+
class CantSendEmptyMessageError(Exception):
|
|
73
|
+
pass
|
|
74
|
+
class WrongParameterError(Exception):
|
|
75
|
+
pass
|