Python聊天机器人

CONTENTS

itchatdoc

Tutorial

图灵机器人

 

 

itchatdoc 

 1 # components.login
 2 login                       = originInstance.login
 3 get_QRuuid                  = originInstance.get_QRuuid
 4 get_QR                      = originInstance.get_QR
 5 check_login                 = originInstance.check_login
 6 web_init                    = originInstance.web_init
 7 show_mobile_login           = originInstance.show_mobile_login
 8 start_receiving             = originInstance.start_receiving
 9 get_msg                     = originInstance.get_msg
10 logout                      = originInstance.logout
11 # components.contact
12 update_chatroom             = originInstance.update_chatroom
13 update_friend               = originInstance.update_friend
14 get_contact                 = originInstance.get_contact
15 get_friends                 = originInstance.get_friends
16 get_chatrooms               = originInstance.get_chatrooms
17 get_mps                     = originInstance.get_mps
18 set_alias                   = originInstance.set_alias
19 set_pinned                  = originInstance.set_pinned
20 add_friend                  = originInstance.add_friend
21 get_head_img                = originInstance.get_head_img
22 create_chatroom             = originInstance.create_chatroom
23 set_chatroom_name           = originInstance.set_chatroom_name
24 delete_member_from_chatroom = originInstance.delete_member_from_chatroom
25 add_member_into_chatroom    = originInstance.add_member_into_chatroom
26 # components.messages
27 send_raw_msg                = originInstance.send_raw_msg
28 send_msg                    = originInstance.send_msg
29 upload_file                 = originInstance.upload_file
30 send_file                   = originInstance.send_file
31 send_image                  = originInstance.send_image
32 send_video                  = originInstance.send_video
33 send                        = originInstance.send
34 # components.hotreload
35 dump_login_status           = originInstance.dump_login_status
36 load_login_status           = originInstance.load_login_status
37 # components.register
38 auto_login                  = originInstance.auto_login
39 configured_reply            = originInstance.configured_reply
40 msg_register                = originInstance.msg_register
41 run                         = originInstance.run
42 # other functions
43 search_friends              = originInstance.search_friends
44 search_chatrooms            = originInstance.search_chatrooms
45 search_mps                  = originInstance.search_mps
46 set_logging   
__init__.py

 

 

返回首页

 

 

 

Tutorial

itchat.auto_login(hotReload=True,enableCmdQR=True)

 

autoreply.py:

Python聊天机器人_第1张图片

import itchat

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):

    return msg['Text']


itchat.auto_login(hotReload=True,enableCmdQR=True)
itchat.run()
View Code

 

sendinfo.py:

Python聊天机器人_第2张图片

import itchat

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    itchat.send(msg['Text'], msg['FromUserName'])

itchat.auto_login(hotReload=True,enableCmdQR=True)
itchat.run()
View Code

 

 

 

getinfo.py:

Python聊天机器人_第3张图片  

import itchat

@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
    print(msg['Text'])

itchat.auto_login(hotReload=True,enableCmdQR=True)
itchat.run()
View Code

 

  

返回首页

 

 

 

图灵机器人

myapikey: 809c72d662374992b355f61653be5a43

 

tulingTest.py:

Python聊天机器人_第4张图片

#coding=utf8
import requests

apiUrl = 'http://www.tuling123.com/openapi/api'

data = {
            'key'    : '809c72d662374992b355f61653be5a43',
            'info'   : '花自飘零水自流', 
            'userid' : 'wechat-robot',
        }

ret = requests.post(apiUrl, data=data).json()

print(ret)
View Code

 

tulingrobot.py:

#coding=utf8
import requests
import itchat

key = "809c72d662374992b355f61653be5a43"

def get_response(msg):

    apiUrl = 'http://www.tuling123.com/openapi/api'

    data = {
                'key'    : key,
                'info'   : msg,
                'userid' : 'wechat-robot',
            }

    ret = requests.post(apiUrl, data = data).json()

    return ret


@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):

    return ("千寻叫兽:" + get_response(msg["Text"])["text"])

itchat.auto_login(hotReload=True,enableCmdQR=True)
itchat.run()
View Code

 

 

返回首页

 

转载于:https://www.cnblogs.com/yan1314/articles/9069657.html

你可能感兴趣的:(python,json)