這篇文章主要介紹如何使用python實現(xiàn)向微信用戶發(fā)送每日一句,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

具體內(nèi)容如下
用Python實現(xiàn)向微信用戶發(fā)送每日一句
# -*- coding:utf-8 -*-
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
#bot = Bot()
#bot = Bot(console_qr=2,cache_path="botoo.pkl")#這里的二維碼是用像素的形式打印出來!,如果你在win環(huán)境上運行,替換為 bot=Bot()
bot = Bot(cache_path=True)
def get_news1():
#獲取金山詞霸每日一句,英文和翻譯
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_news1()[0])
my_friend.send(get_news1()[1][5:])
my_friend.send(u"以上是金山詞霸每日一句,http://www.qq.com\" data-miniprogram-appid=\"wxae430cc3e778834b\" data-miniprogram-path=\"pages/goLogin/goLogin\"")
t = Timer(10, send_news)#每86400秒(1天),發(fā)送1次,不用linux的定時任務(wù)是因為每次登陸都需要掃描二維碼登陸,很麻煩的一件事,就讓他一直掛著吧
t.start()
except:
my_friend = bot.friends().search('回憶總是如此傷')[0]#你的微信名稱,不是微信帳號。
my_friend.send(u"今天消息發(fā)送失敗了")
if __name__ == "__main__":
send_news()用Python調(diào)用圖靈機器人接口實現(xiàn)微信聊天機器人
import kivy
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.button import Button
import itchat
import requests
class test(App):
def get_response(msg):
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key': '0646d90819004f2fa565852c0fe3c3af', # Tuling Key
'info': msg, # 這是我們發(fā)出去的消息
'userid': '123', # 這里你想改什么都可以
}
# 我們通過如下命令發(fā)送一個post請求
r = requests.post(apiUrl, data=data).json()
return r.get('text')
@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
return get_response(msg['Text'])
@itchat.msg_register([itchat.content.TEXT], isGroupChat=True)
def print_content(msg):
return get_response(msg['Text'])
itchat.auto_login(True)
itchat.run()
if __name__ == '__main__':
test().run()以上是“如何使用python實現(xiàn)向微信用戶發(fā)送每日一句”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
新聞標題:如何使用python實現(xiàn)向微信用戶發(fā)送每日一句-創(chuàng)新互聯(lián)
本文來源:http://www.chinadenli.net/article20/iidjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、Google、搜索引擎優(yōu)化、App設(shè)計、小程序開發(fā)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容