from __future__ import unicode_literals import requests import itchat import time 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: # 登陆你的微信账号,会弹出网页二维码,扫描即可 itchat.auto_login(hotReload=True) # 改成你最心爱的人的名字。 my_friend = itchat.search_friends(name=u'要发的人') # 获取对应名称的一串数字 XiaoMing = my_friend[0]["UserName"] # 消息设置 message3 = "来自微信自动化测试" # 发送消息 for i in range(1, 10): itchat.send(message3, toUserName=XiaoMing) # t = time(1, send_news()) # t.start() except: message4 = u"/(ㄒoㄒ)/~~" itchat.send(message4, toUserName=XiaoMing) def main(): send_news() if __name__ == '__main__': main()