亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python實(shí)現(xiàn)給微信指定好友定時(shí)發(fā)送消息

 更新時(shí)間:2019年04月29日 15:04:07   作者:蹦跶的小羊羔  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)給微信指定好友定時(shí)發(fā)消息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

python有很多有趣的庫,其中wxpy是連接微信的接口,具體可以查看官方文檔??梢詫?shí)現(xiàn)自動(dòng)操作,wxpy 支持 Python 3.4-3.6,以及 2.7 版本。

一、安裝

win10環(huán)境,直接在cmd中,輸入

pip install wxpy

有時(shí)網(wǎng)絡(luò)不穩(wěn)定,可能出現(xiàn)錯(cuò)誤,重新執(zhí)行操作嘗試一下。

二、簡單介紹

# 導(dǎo)入模塊
from wxpy import *
# 初始化機(jī)器人,掃碼登陸
bot = Bot()
# 搜索名稱含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]

三、詳細(xì)代碼

打開cmd,執(zhí)行jupyter notebook,打開ipython環(huán)境,在打開的瀏覽器頁面中,新建一個(gè)python3的ipynb文件。

from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
 
bot = None
def get_news():
 #獲取一個(gè)連接中的內(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"咦?我是自動(dòng)人!!")
  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é)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論