使用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"消息發送失敗了")