Python itchat个人微信账号接口定时发送群消息
2017-10-21 11:36
1071 查看
需求说明
媳妇儿又换工作了,这次是有关运营的,具体什么是运营我也不知道,有一项工作内容是使用微信定时的往微信群里发送指定的信息,来维护,她问我这个东西可不可以自动化,于是乎就研究了一下,找到了python的itchat这个工具,就写了一下。
功能点
使用微信,定时往指定的微信群里发送指定信息
需要发送的内容使用excel进行维护,指定要发送的微信群名、时间、内容
技术点
itchat:这个是主要的工具,用于连接微信个人账号接口。以下是一些相关的知识点网站
http://itchat.readthedocs.io/zh/latest/
https://segmentfault.com/a/1190000009420701
xlrd:这个是用来读Excel文件的工具
apscheduler:这个是用来定时调度时间的工具
以上工具可以使用pip install进行安装
有些库包无法进行在线安装,可以在以下的网站搜索下载,然后使用pip install 文件名 这种方式进行安装
http://www.lfd.uci.edu/~gohlke/pythonlibs/
代码
Excel文件截图示例
启动程序命令以及截图示例
启动程序命令:python main.py
在启动后,界面会出现一个二维码,用微信扫描即可登录
媳妇儿又换工作了,这次是有关运营的,具体什么是运营我也不知道,有一项工作内容是使用微信定时的往微信群里发送指定的信息,来维护,她问我这个东西可不可以自动化,于是乎就研究了一下,找到了python的itchat这个工具,就写了一下。
功能点
使用微信,定时往指定的微信群里发送指定信息
需要发送的内容使用excel进行维护,指定要发送的微信群名、时间、内容
技术点
itchat:这个是主要的工具,用于连接微信个人账号接口。以下是一些相关的知识点网站
http://itchat.readthedocs.io/zh/latest/
https://segmentfault.com/a/1190000009420701
xlrd:这个是用来读Excel文件的工具
apscheduler:这个是用来定时调度时间的工具
以上工具可以使用pip install进行安装
有些库包无法进行在线安装,可以在以下的网站搜索下载,然后使用pip install 文件名 这种方式进行安装
http://www.lfd.uci.edu/~gohlke/pythonlibs/
代码
# coding=utf-8 from datetime import datetime import itchat import xlrd from apscheduler.schedulers.background import BlockingScheduler import os def SentChatRoomsMsg(name, context): itchat.get_chatrooms(update=True) iRoom = itchat.search_chatrooms(name) for room in iRoom: if room['NickName'] == name: userName = room['UserName'] break itchat.send_msg(context, userName) print("发送时间:" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n" "发送到:" + name + "\n" "发送内容:" + context + "\n") print("*********************************************************************************") scheduler.print_jobs() def loginCallback(): print("***登录成功***") def exitCallback(): print("***已退出***") itchat.auto_login(hotReload=True, enableCmdQR=True, loginCallback=loginCallback, exitCallback=exitCallback) workbook = xlrd.open_workbook( os.path.join(os.path.dirname(os.path.realpath(__file__)), "chatroomsfile\AutoSentChatroom.xlsx")) # workbook = xlrd.open_workbook("D:\PyCharmCode\AutoLiulishouWechat\chatroomsfile\AutoSentChatroom.xlsx") sheet = workbook.sheet_by_name('Chatrooms') iRows = sheet.nrows scheduler = BlockingScheduler() index = 1 for i in range(1, iRows): textList = sheet.row_values(i) name = textList[0] context = textList[2] float_dateTime = textList[1] date_value = xlrd.xldate_as_tuple(float_dateTime, workbook.datemode) date_value = datetime(*date_value[:5]) if datetime.now() > date_value: continue date_value = date_value.strftime('%Y-%m-%d %H:%M:%S') textList[1] = date_value scheduler.add_job(SentChatRoomsMsg, 'date', run_date=date_value, kwargs={"name": name, "context": context}) print("任务" + str(index) + ":\n" "待发送时间:" + date_value + "\n" "待发送到:" + name + "\n" "待发送内容:" + context + "\n" "******************************************************************************\n") index = index + 1 if index == 1: print("***没有任务需要执行***") scheduler.start()
Excel文件截图示例
启动程序命令以及截图示例
启动程序命令:python main.py
在启动后,界面会出现一个二维码,用微信扫描即可登录
相关文章推荐
- 在python中使用itchat发送微信消息
- python使用itchat发送微信消息提醒
- 在python中使用itchat发送微信消息
- 使用Python itchat个人微信账号头像拼接
- python实现微信接口(itchat)
- python实现微信接口(itchat)
- 安装python itchat 模块 用python发微信消息
- 有了 itchat, python 调用微信个人号从未如此简单(新增 py3 支持)
- python-itchat微信消息群发、自动回复
- 微信开发 python django 多客服接口发送到客户端的消息乱码
- itchat 批量给微信好友发送祝福消息
- 使用Python微信库itchat获得好友和群组已撤回的消息
- python实现微信接口(itchat)详细介绍
- python实现微信接口(itchat)
- itchat 微信接口不能直接发消息给指定用户
- python实现微信接口(itchat)
- 通过itchat进行给好友发送消息
- Java微信二次开发(二) Java微信文本消息接口请求与发送
- Python实现微信好友签名词云的构建(itchat、jieba、wordcloud)
- [实例]JAVA调用微信接口发送图文消息,不用跳到详情页