Python3 itchat实现微信定时发送群消息
Python3 itchat实现微信定时发送群消息
一、简介
1,使用微信,定时往指定的微信群里发送指定信息。
2,需要发送的内容使用excel进行维护,指定要发送的微信群名、时间、内容。
二、py库
1,itchat:这个是主要的工具,用于连接微信个人账号接口。以下是一些相关的知识点网站。
2,xlrd:这个是用来读Excel文件的工具。
3,apscheduler:这个是用来定时调度时间的工具。
三、实例代码
# 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()
Python3 itchat实现微信定时发送群消息的更多相关文章
- Python3 使用企业微信 API 发送消息
#coding=utf- import requests import json Secret = "TUbfeW8nFQakwOS4czm13SCnxSUPOqY2K0XHtM8XLT34 ...
- 用python自制微信机器人,定时发送天气预报
0 引言 前段时间找到了一个免费的天气预报API,费了好段时间把这个API解析并组装成自己想用的格式了,就想着如何实现每天发送天气信息给自己.最近无意中发现了wxpy库,用它来做再合适不过了.以下是w ...
- python实现定时发送系列
1.发送邮件实现 2.定时任务实现 3.定时发送邮件实现 4.微信定时发送信息 详细源代码见:https://github.com/15387062910/timing_send 参考: 廖雪峰博客 ...
- 全网最全的Windows下Python2 / Python3里正确下载安装用来向微信好友发送消息的itchat库(图文详解)
不多说,直接上干货! 建议,你用Anaconda2或Anaconda3. 见 全网最全的Windows下Anaconda2 / Anaconda3里正确下载安装用来向微信好友发送消息的itchat库( ...
- 全网最全的Windows下Anaconda2 / Anaconda3里Python语言实现定时发送微信消息给好友或群里(图文详解)
不多说,直接上干货! 缘由: (1)最近看到情侣零点送祝福,感觉还是很浪漫的事情,相信有很多人熬夜为了给爱的人送上零点祝福,但是有时等着等着就睡着了或者时间并不是卡的那么准就有点强迫症了,这是也许程序 ...
- Python3 itchat微信获取好友、公众号、群聊的基础信息
Python3 itchat微信获取好友.公众号.群聊的基础信息 一.简介 安装 itchat pip install itchat 使用个人微信的过程当中主要有三种账号需要获取,分别为: 好友 公众 ...
- 基于itchat实现微信群消息同步机器人
原始网址:http://www.jianshu.com/p/7aeadca0c9bd# 最近 全栈数据工程师养成攻略 的微信群已经将近500人,开了二群之后为了打通不同微信群之间的消息,花了点时间做了 ...
- 利用python itchat给女朋友定时发信息
利用itchat给女朋友定时发信息 涉及到的技术有itchat,redis,mysql,最主要的还是mysql咯,当然咯,这么多东西,我就只介绍我代码需要用到的,其他的,如果需要了解的话,就需要看参考 ...
- 10分钟教你用Python打造天气机器人+关键字自动回复+定时发送
01 前言 Hello,各位小伙伴.自上次我们介绍了Python实现天气预报的功能以后,那个小程序还有诸多不完善的地方,今天,我们再次来完善一下我们的小程序.比如我们想给机器人发“天气”等关键字,它就 ...
随机推荐
- uploadify3.2.1 多文件上传总是只能上传一个文件
再网上找了老半天原因,有人说是上传时调用方法参数应该加上*号(:$('#mulfile_upload').uploadify('upload','*');) 总是不行, 我怀疑下面的原因: 我就以为是 ...
- POJ--3321 Apple Tree(树状数组+dfs(序列))
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22613 Accepted: 6875 Descripti ...
- ububtu16.04下安装protobuf
重新下载protobuf,我下载的时最新的protobuf-all-3.5.1.tar.gz protobuf网址:https://github.com/google/protobuf/relea ...
- Python数据分析必备Anaconda安装、快捷键、包安装
Python数据分析必备: 1.Anaconda操作 Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便 ...
- 蓝桥杯 - G将军有一支训练有素的军队 - [树形DP]
G将军有一支训练有素的军队,这个军队除开G将军外,每名士兵都有一个直接上级(可能是其他士兵,也可能是G将军).现在G将军将接受一个特别的任务,需要派遣一部分士兵(至少一个)组成一个敢死队,为了增加敢死 ...
- HDU 4849 - Wow! Such City!
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others) Input There ar ...
- Pymongo NotMasterError while fetching count of the collection as per query from MongoDB in DRF
django rest framework - Pymongo NotMasterError while fetching count of the collection as per query f ...
- 场景服务只创建了 Service Difinition 和feature layer
环境:物理机 pro1.4:虚拟机 (server + datastore + portal + adaptor) 10.4.1 发布场景服务,正常情况应portal中查看,应包含四部分内容:Serv ...
- css3的一个小demo(箭头hover变化)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mysql数据库的相关练习题及答案
表结构示意图: 表结构创建语句: class表创建语句 create table ) not null)engine=innodb default charset=utf8; student表创建语句 ...