python实现微信每日一句自动发送给喜欢的人

Eliza ·
更新时间:2024-09-21
· 855 次阅读

本文实例为大家分享了python实现微信每日一句自动发送的具体代码,供大家参考,具体内容如下

参考了一篇博客:教你使用python实现微信每天给女朋友说晚安

代码:

# -*- coding: utf-8 -*- ''' 这是一个用来测试微信自动发送消息的demo 恩,主要就是用到了一个微信库--wxpy 安装很简单 pip install wxpy 下面就开始吧 主要就两个函数 1、getNews();用以获取信息 2、sendNews();用以发送信息 我这里发送消息用的是for循环本意是群发,但是!但是!但是!程序发的太快会被微信禁掉,大概40个人左右就会被禁,以后可以试试sleep一下。 另外vscode中自定义python编译器: Ctrl+shift+p, 选择 python: Select Interpreter ''' from __future__ import unicode_literals from wxpy import * import requests from threading import Timer itchat = Bot(console_qr=2,cache_path="botoo.pkl") def getNews(): url = "http://open.iciba.com/dsapi/" r = requests.get(url) content = r.json()['content'] note = r.json()['note'] return content, note def sendNews(): try: #这里是备注 friend = itchat.friends().search(name = u'xxx') content = getNews() print(content) message1 = str(content[0]) message2 = str(content[1]) message3 = "xxx" print(friend) for index,item in enumerate(friend): print("发送给 "+str(item)+" ing,index="+str(index)) item.send(message1) item.send(message2) item.send(message3) t = Timer(86400,sendNews) t.start() except: errorMessage = "xxx" for index,item in enumerate(friend): item.send(errorMessage) if __name__ == "__main__": sendNews() 您可能感兴趣的文章:Python 网络编程起步(Socket发送消息)python实现给微信公众号发送消息的方法Python微信企业号开发之回调模式接收微信端客户端发送消息及被动返回消息示例python模仿网页版微信发送消息功能Python定时发送消息的脚本:每天跟你女朋友说晚安python实现微信定时每天和女友发送消息python实现给微信指定好友定时发送消息python3+pyqt5+itchat微信定时发送消息的方法使用python3调用wxpy模块监控linux日志并定时发送消息给群组或好友基于Python实现定时自动给微信好友发送天气预报python实现的自动发送消息功能详解



每日一句 自动 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号