python實現(xiàn)給微信指定好友定時發(fā)送消息
python有很多有趣的庫,其中wxpy是連接微信的接口,具體可以查看官方文檔??梢詫崿F(xiàn)自動操作,wxpy 支持 Python 3.4-3.6,以及 2.7 版本。
一、安裝
win10環(huán)境,直接在cmd中,輸入
pip install wxpy
有時網(wǎng)絡(luò)不穩(wěn)定,可能出現(xiàn)錯誤,重新執(zhí)行操作嘗試一下。
二、簡單介紹
# 導(dǎo)入模塊 from wxpy import * # 初始化機器人,掃碼登陸 bot = Bot()
# 搜索名稱含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]
三、詳細代碼
打開cmd,執(zhí)行jupyter notebook,打開ipython環(huán)境,在打開的瀏覽器頁面中,新建一個python3的ipynb文件。
from __future__ import unicode_literals from threading import Timer from wxpy import * import requests bot = None def get_news(): #獲取一個連接中的內(nèi)容 url = "http://open.iciba.com/dsapi/" r = requests.get(url) print(r.json()) contents = r.json()['content'] translation = r.json()['translation'] return contents,translation def login_wechat(): global bot bot = Bot() # bot = Bot(console_qr=2,cache_path="botoo.pkl")#linux環(huán)境上使用 def send_news(): if bot == None: login_wechat() try: my_friend = bot.friends().search(u'xxx')[0] #xxx表示微信昵稱 my_friend.send(get_news()[0]) my_friend.send(get_news()[1][5:]) my_friend.send(u"咦?我是自動人??!") t = Timer(360, send_news) #360是秒數(shù) t.start() except: print(u"失?。?!") if __name__ == "__main__": send_news() print(get_news()[0])
然后按ctrl+enter鍵執(zhí)行。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
探究數(shù)組排序提升Python程序的循環(huán)的運行效率的原因
這篇文章主要介紹了探究數(shù)組排序提升Python程序的循環(huán)的運行效率的原因,作者用代碼實踐了多個小片段來進行對比解釋,需要的朋友可以參考下2015-04-04
Python多任務(wù)版靜態(tài)Web服務(wù)器實現(xiàn)示例
這篇文章主要為大家介紹了Python靜態(tài)Web服務(wù)器多任務(wù)版實現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06
Python 實現(xiàn)opencv所使用的圖片格式與 base64 轉(zhuǎn)換
今天小編就為大家分享一篇Python 實現(xiàn)opencv所使用的圖片格式與 base64 轉(zhuǎn)換,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01
python實現(xiàn)字符串中字符分類及個數(shù)統(tǒng)計
這篇文章主要介紹了python實現(xiàn)字符串中字符分類及個數(shù)統(tǒng)計,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-09-09

