首页 > 微信 > 详细

通过python,定时发送微信消息

时间:2019-12-15 22:29:00      阅读:203      评论:0      收藏:0      [点我收藏+]
# -*- coding: UTF-8 -*-
import itchat
import time
import requests
def get_new():
url="http://open.iciba.com/dsapi"
r=requests.get(url)
contents=r.json()[‘content‘]
translation=r.json()[‘note‘]
return contents,translation
def send_news():
try:
itchat.auto_login(hotReload=True)
my_friend=itchat.search_friends(name=u‘卡2‘)
FriendName=my_friend[0]["UserName"]
message1=get_new()[0]
#因为会出现进程报错,所以我加上了 pass
pass
content=get_new()[1]
pass
message2=content
pass
message3=u"来自你的朋友"
pass
itchat.send(message1,toUserName=FriendName)
itchat.send(message2, toUserName=FriendName)
itchat.send(message3, toUserName=FriendName)
#每个1天发送消息
t=time(86400,send_news())
t.start()

except:
#如果上面其中一条消息没有发送成功,就会发送本条消息
message4=u"你的朋友出bug了"
itchat.send(message4,toUserName=FriendName)

if __name__=="__main__":
send_news()

通过python,定时发送微信消息

原文:https://www.cnblogs.com/benpao-yezi/p/12046067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!