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

时间:2021-05-22

本文实例为大家分享了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_literalsfrom wxpy import *import requestsfrom threading import Timeritchat = 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, notedef 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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章