所需要的库
pip install wxpy
pip install requests
#!/usr/bin/python # -*- coding:utf-8 -*- from __future__ import unicode_literals from threading import Timer from wxpy import * import requests bot = Bot() def get_news(): # 获取金山词霸每日一句,英文和翻译 url = "http://open.iciba.com/dsapi" r = requests.get(url) contents = r.json()['content'] translation = r.json()['translation'] return contents, translation def send_news(): try: my_friend = bot.friends().search(u'微信名称')[0] # 你朋友的微信名称,不是备注,也不是微信账号 my_friend.send(get_news()[0]) my_friend.send(get_news()[1][5:]) my_friend.send(u"来自爸爸的心灵鸡汤!") except: my_friend = bot.friends().search(u'微信名称')[0] my_friend.send(u"今天消息发送失败了") if __name__ == "__main__": send_news()