使用python3.6环境
话不多说直接上代码
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
bot = Bot()
def get_data():
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
contents = r.json()['content']
translation = r.json()['translation']
return contents, translation
def send_data():
try:
my_friend = bot.friends().search(u'Perdidas')[0]
my_friend.send(get_data()[0])
my_friend.send(get_data()[1][5:])
my_friend.send(u"--心灵鸡汤!")
t = Timer(8, send_data)
t.start()
except:
my_friend = bot.friends().search('Perdidas')[0]
my_friend.send(u"消息发送失败了")