from __future__ import unicode_literals from threading import Timer from wxpy import * import requests bot = Bot() def get_data(): # 金山词霸每日一句,英文和翻译 url = "http://open.iciba测试数据/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"--心灵鸡汤!") # 每8秒,发送1次 t = Timer(8, send_data) t.start() except: # 你的微信名称。 my_friend = bot.friends().search(‘Perdidas‘)[0] my_friend.send(u"消息发送失败了") send_data()
更多技术咨询可关注:gzitcast
查看更多关于使用python定时发送微信信息的详细内容...