# -*- 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()