python與圖靈機器人交互(WXPY版本)


開發者賬號:wujunfeng , 開發者key:官網申請 

#!/usr/bin/env python
#-*- coding:utf-8 -*- @Author : wujf @Time:2018/9/4 15:21

from wxpy import *

# 掃碼登陸
bot = Bot(cache_path=False)

# 初始化圖靈機器人 (API key 申請: http://tuling123.com)
tuling = Tuling(api_key='3b802c35c40510414bb6d77b4f563661')

myfriend = bot.friends().search(u'鄒唯')[0]
# 自動回復所有文字消息
# @bot.register(msg_types=TEXT)
# def auto_reply_all(msg):
# tuling.do_reply(msg)
#
#
# # 開始運行
# bot.join()
#回復指定好友
@bot.register(myfriend)
def auto_reply_all(msg):
tuling.do_reply(msg)

# 開始運行
bot.join()

缺點:機器人比較弱智。想要聰明的機器人可以看我其他關於機器人的介紹

#############################################給指定好友發送消息#####################################

或者

'''itchat'''
import itchat
itchat.auto_login(hotReload=True)
#friends_list = itchat.get_friends(update=True)
name = itchat.search_friends(name=u'王林')
Wanglin = name[0]["UserName"]
itchat.send('1',toUserName=Wanglin)
使用itchat也可以指定給某人發送消息。


'''wxpy'''

from wxpy import *
bot = Bot(cache_path=True)
my_frends = bot.friends().search(u'王林')[0]
my_frends.send('11') #給朋友發消息
bot.file_helper.send('Hello World!') #給文件助手發消息
bot.self.send('Hello World!') #給機器人自己發消息
print(my_frends)





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM