一、用Python自动发送微信消息
import itchat
itchat.auto_login(enableCmdQR=True,hotReload=True)
to_room = itchat.search_chatrooms(name='群聊名称')
for i in range(10):
itchat.send('需要发送的文字信息',toUserName=to_room[0]['UserName'])
二、用Python自动接收 并 回复微信消息,同时把接收的文件进行自动保存
from itchat.content import *
@itchat.msg_register(TEXT)
def text_reply(msg):
print(msg.text)
reply_text = msg.text.replace('吗?','!')
return reply_text
itchat.auto_login(enableCmdQR=True,hotReload=True)
itchat.run()
三、在文件被修改后实时发送修改的信息给指定的微信好友
import os
import time
import xlrd
import itchat
itchat.auto_login(enableCmdQR=True,hotReload=True)
change_time_save = time.ctime(os.stat('aaa.xlsx').st_mtime)
while True:
time.sleep(5)
change_time = time.ctime(os.stat('aaa.xlsx').st_mtime)
if change_time_save == change_time:
pass
else:
change_time_save = change_time
xlsx = xlrd.open_workbook('aaa.xlsx')
table = xlsx.sheet_by_index(0)
content = str(table.cell_value(0,0))
to_name = itchat.search_friends(name='微信好友备注名')
itchat.send(content,toUserName=to_name[0]['UserName'])
print("发送成功!时间:" + time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))