python定时发送微信信息
安装库:
发送一次信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| from wxauto import * import time
def message_auto_one(user, message): if time_now >= time_send: wx = WeChat() wx.GetSessionList() wx.ChatWith(user) wx.SendMsg(message) print("一次成功") exit() else: print("发送时间:", time_send, "现在时间:", time_now) time.sleep(5)
if __name__ == "__main__": time_send = '12:30:00' message_send = '12:30:信息正常发送' user_send = '文件传输助手' while True: time_now = time.strftime("%H:%M:%S", time.localtime()) message_auto_one(user_send, message_send)
|
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
| from wxauto import * import time
def message_auto_one(user, message): if time_now >= time_send: wx.ChatWith(user) wx.SendMsg(message) exit() else: time.sleep(5) print("发送时间:", time_send, "现在时间:", time_now)
def message_auto_more(user, message): if time_now >= time_send: WxUtils.SetClipboard(message) wx.ChatWith(user) wx.SendClipboard() exit() else: print("发送时间:", time_send, "现在时间:", time_now) time.sleep(5)
if __name__ == "__main__": time_send = '16:00:00' user_send = '文件传输助手' message_send_one = '没意思' message_send_more = '''这是第一行\n这是第二行\n这是第三行\n这是第四行'''
wx = WeChat() wx.GetSessionList() while True: time_now = time.strftime("%H:%M:%S", time.localtime()) # message_auto_one(user_send, message_send_one) message_auto_more(user_send, message_send_more)
|
循环发送信息:
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
| from wxauto import * import time import sys
def judgment(): global number try: wx = WeChat() wx.GetSessionList() wx.ChatWith(user_send) wx.SendMsg(message_send) time_ok = time.strftime("%H:%M:%S") print("{0}次成功".format(number), "完成时间:", time_ok) except Exception as e: print(e) number += 1 judgment()
def message_auto_send(): global flag time_part = time.strftime("%p") time_now = time.strftime("%H:%M:%S") if time_send['frame'] == time_part: if time_now >= time_send['auto']: judgment() flag = flag + 1 print("第{0}个消息发送成功".format(flag)) else: print("发送时间:", time_send['auto'], "现在时间:", time_now) time.sleep(5) message_auto_send() else: print("发送时间:", time_send['auto'], "现在时间:", time_now) time.sleep(5) message_auto_send()
if __name__ == "__main__": flag = 0 number = 1 sys.setrecursionlimit(10000) user_send = '文件传输助手'
# time_send = {'auto':'17:00:00', 'frame':'PM'} # message_send = '17:00 信息发送成功' # message_auto_send()
# time_send = {'auto':'18:00:00', 'frame':'PM'} # message_send = '17:00 信息发送成功' # message_auto_send()
time_send = {'auto':'18:00:00', 'frame':'AM'} message_send = '19:00 信息发送成功' message_auto_send()
|
import time
from wxauto import WeChat
def send_message(user, message):
try:
wx = WeChat()
wx.GetSessionList()
wx.ChatWith(user)
wx.SendMsg(message)
print(f"消息发送成功,完成时间:{time.strftime('%H:%M:%S')}")
except Exception as e:
print(e)
def auto_send_message(user, message, time_send, time_fram):
while True:
time_part = time.strftime("%p")
time_now = time.strftime("%H:%M:%S")
if time_part == time_fram and time_now >= time_send:
send_message(user, message)
print(f"消息发送成功,完成时间:{time.strftime('%H:%M:%S')}")
time.sleep(10)
break
else:
print(f"发送时间{time_send},当前时间{time_now}")
time.sleep(10)
continue
if __name__ == "__main__":
user_send = '文件传输助手'
tasks = [
{'auto':'17:00:00', 'frame':'PM', 'message':'17:00 信息发送成功'},
{'auto':'18:00:00', 'frame':'PM', 'message':'18:00 信息发送成功'},
{'auto':'19:00:00', 'frame':'AM', 'message':'19:00 信息发送成功'},
]
for task in tasks:
auto_send_message(user_send, task['message'], task['auto'], task['frame'])