pywechat127 1.5.8__py3-none-any.whl

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.
pywechat/Clock.py ADDED
@@ -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
pywechat/Errors.py ADDED
@@ -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
pywechat/Uielements.py ADDED
@@ -0,0 +1,81 @@
1
+ '''
2
+ Uielements
3
+ ---------
4
+ PC微信中的各种Ui-Object'''
5
+ class Login_window():
6
+ '''登录界面要用到的唯二的两个Ui:登录界面与进入微信按钮\n'''
7
+ LoginWindow={'title':'微信','class_name':'WeChatLoginWndForPC','visible_only':False}
8
+ LoginButton={'title':'进入微信','control_type':'Button'}
9
+
10
+ class ToolBar():
11
+ '''主界面导航栏下的所有Ui'''
12
+ Chat={'title':'聊天','control_type':'Button'}
13
+ Contacts={'title':'通讯录','control_type':'Button'}
14
+ Collections={'title':'收藏','control_type':'Button'}
15
+ ChatFiles={'title':'聊天文件','control_type':'Button'}
16
+ Moments={'title':'朋友圈','control_type':'Button'}
17
+ Channel={'title':'视频号','control_type':'Button'}
18
+ Topstories={'title':'看一看','control_type':'Button'}
19
+ Search={'title':'搜一搜','control_type':'Button'}
20
+ Miniprogram_pane={'title':'小程序面板','control_type':'Button'}
21
+ SettingsAndOthers={'title':'设置及其他','control_type':'Button'}
22
+
23
+
24
+ class Main_window():
25
+ '''主界面下所有的第一级Ui\n'''
26
+ AddTalkMemberWindow={'title':'AddTalkMemberWnd','control_type':'Window','class_name':'AddTalkMemberWnd','framework_id':'Win32'}
27
+ MainWindow={'title':'微信','class_name':'WeChatMainWndForPC'}
28
+ Toolbar={'title':'导航','control_type':'ToolBar'}
29
+ MessageList={'title':'会话','control_type':'List'}
30
+ Search={'title':'搜索','control_type':'Edit'}
31
+ SearchResult={'title_re':"@str:IDS_FAV_SEARCH_RESULT",'control_type':'List'}
32
+ CerateGroupChatButton={'title':"发起群聊",'control_type':"Button"}
33
+ ChatToolBar={'title':'','found_index':0,'control_type':'ToolBar'}
34
+ ChatMessage={'title':'聊天信息','control_type':'Button'}
35
+ CurrentChatWindow={'control_type':'Edit','found_index':1}
36
+ CerateNewNote={'title':'新建笔记','control_type':'Button'}
37
+ ProfileWindow={'class_name':"ContactProfileWnd",'control_type':'Pane','framework_id':'Win32'}
38
+ MoreButton={'title':'更多','control_type':'Button'}
39
+ FriendMenu={'control_type':'Menu','title':'','class_name':'CMenuWnd','framework_id':'Win32'}
40
+ FriendSettingsWindow={'class_name':'SessionChatRoomDetailWnd','control_type':'Pane','framework_id':'Win32'}
41
+ GroupSettingsWindow={'title':'SessionChatRoomDetailWnd','control_type':'Pane','framework_id':'Win32'}
42
+ SettingsMenu={'class_name':'SetMenuWnd','control_type':'Window'}
43
+ SettingsButton={'title':'设置','control_type':'Button'}
44
+ ContactsManage={'title':'通讯录管理','control_type':'Button'}
45
+ ContactsList={'title':'联系人','control_type':'List'}
46
+ AddNewFriendButon={'title':'添加朋友','control_type':'Button'}
47
+ SearchNewFriendBar={'title':'微信号/手机号','control_type':'Edit'}
48
+ SearchNewFriendResult={'title_re':'@str:IDS_FAV_SEARCH_RESULT','control_type':'List'}
49
+ AddFriendRequestWindow={'title':'添加朋友请求','class_name':'WeUIDialog','control_type':'Window','framework_id':'Win32'}
50
+ AddMemberWindow={'title':'AddMemberWnd','control_type':'Window','framework_id':'Win32'}
51
+ DeleteMemberWindow={'title':'DeleteMemberWnd','control_type':'Window','framework_id':'Win32'}
52
+ QuitGroupButton={'title':"退出",'control_type':'Button'}
53
+ EmptyChatHistoryButon={'title':'清空','control_type':'Button'}
54
+ Tickle={'title':'拍一拍','control_type':'MenuItem'}
55
+ SelectContactWindow={'title':'','control_type':'Window','class_name':'SelectContactWnd','framework_id':'Win32'}
56
+ SetTag={'title':'设置标签','framework_id':'Win32','class_name':'StandardConfirmDialog'}
57
+ FriendChatList={'title':'消息','control_type':'List'}
58
+ CantSendEmptyMessageTips={'title':'不能发送空白信息','control_type':'Text'}
59
+
60
+ class Independent_window():
61
+ '''独立于微信主界面,将微信主界面关闭后仍能在桌面显示的Ui\n'''
62
+ Desktop={'backend':'uia'}
63
+ SettingWindow={'title':'设置','class_name':"SettingWnd",'control_type':'Window'}
64
+ ContactManagerWindow={'title':'通讯录管理','class_name':'ContactManagerWindow'}
65
+ MomentsWindow={'title':'朋友圈','control_type':"Window",'class_name':"SnsWnd"}
66
+ ChatFilesWindow={'title':'聊天文件','control_type':'Window','class_name':'FileListMgrWnd'}
67
+ MiniProgramWindow={'title':'微信','control_type':'Pane','class_name':'Chrome_WidgetWin_0'}
68
+ SearchWindow={'title':'微信','class_name':'Chrome_WidgetWin_0','control_type':'Pane'}
69
+ ChannelWindow={'title':'微信','class_name':'Chrome_WidgetWin_0','control_type':'Pane'}
70
+ ContactProfileWindow={'title':'微信','class_name':'ContactProfileWnd','framework_id':'Win32','control_type':'Pane'}
71
+ TopStoriesWindow={'title':'微信','class_name':'Chrome_WidgetWin_0','control_type':'Pane'}
72
+ ChatHistoryWindow={'control_type':'Window','class_name':'FileManagerWnd','framework_id':'Win32'}
73
+ GroupAnnouncementWindow={'title':'群公告','framework_id':'Win32','class_name':'ChatRoomAnnouncementWnd'}
74
+ NoteWindow={'title':'笔记','class_name':'FavNoteWnd','framework_id':"Win32"}
75
+ OldIncomingCallWindow={'class_name':'VoipTrayWnd','title':'微信'}
76
+ NewIncomingCallWindow={'class_name':'ILinkVoipTrayWnd','title':'微信'}
77
+ OldVoiceCallWindow={'title':'微信','class_name':'AudioWnd'}
78
+ NewVoiceCallWindow={'title':'微信','class_name':'ILinkAudioWnd'}
79
+ OldVideoCallWindow={'title':'微信','class_name':'VoipWnd'}
80
+ NewVideoCallWindow={'title':'微信','class_name':'ILinkVoipWnd'}
81
+ OfficialAccountWindow={'title':'公众号','control_type':'Window','class_name':'H5SubscriptionProfileWnd'}
pywechat/Warnings.py ADDED
@@ -0,0 +1,13 @@
1
+
2
+ from warnings import warn
3
+ class LongTextWarning(Warning):
4
+ '''消息字数超长警告'''
5
+ #微信字数限制2000字,超长部分不发送,这时需要转化为word发送
6
+ pass
7
+ class InputMethodWarning(Warning):#使用pywinauto的type_keys方法时
8
+ #电脑的输入法为微信输入法时无法打字,需要及时转换为ctrl+v复制消息发送,并按下win+空格切换一下输入法
9
+ '''输入法警告'''
10
+ pass
11
+ class ChatHistoryNotEnough(Warning):
12
+ '''聊天记录不足指定的个数'''
13
+ pass