正文
调用itchat访问图灵机器人api聊天的小程序,应付一下过年的刷屏群发
之前搞的alice只能回英语,而且略呆傻
图灵api的key去注册账号就有了,网址戳这里
就是这样
Code
# -*- coding: utf-8 -*-
import requests, json
import itchat, aiml, os
from itchat.content import *
@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
def text_reply(msg):
# cont = alice.respond(msg['Text'])
cont = requests.get('http://www.tuling123.com/openapi/api?key=就不告诉你&info=%s' % msg['Content']).content
m = json.loads(cont)
itchat.send(m['text'], msg['FromUserName'])
if m['code'] == 200000:
itchat.send(m['url'], msg['FromUserName'])
if m['code'] == 302000:
itchat.send(m['list'], msg['FromUserName'])
if m['code'] == 308000:
itchat.send(m['list'], msg['FromUserName'])
itchat.auto_login(hotReload = True)
itchat.run()