python騷操作,指定微信好友傳送訊息
阿新 • • 發佈:2019-01-29
python 指定好友傳送訊息
- 大家在測試的時候儘量使用微信小號
- 不要不改程式碼就測試
- 這裡呼叫了金山詞霸的每日一句,你也可以指定文字資訊傳送,七夕快到了,你懂得。
from threading import Timer from wxpy import * import requests bot = Bot()#連線微信,會出現一個登陸微信的二維碼 def get_news(): '''獲取金山詞霸每日一句''' url = 'http://open.iciba.com/dsapi' r = requests.get(url) content = r.json()['content'] note = r.json()['note'] return content,note def send_news(): try: contents = get_news() my_friend =bot.friends().search(u'小明')[0]#這裡是你微信好友的暱稱 my_friend.send(contents[0]) my_friend.send(contents[1]) my_friend.send(u'來自自動回覆') t = Timer(86400,send_news)#這裡是一天傳送一次,86400s = 24h t.start() except: my_friend = bot.friends().search('sixkery')[0]#這裡是你的微信暱稱 my_friend.send(u'今天訊息傳送失敗了') if __name__ == '__main__': send_news()