Using python to implement small robot automatic reply and scalable development of small robots for WeChat public accounts

高洛峰
Release: 2017-03-27 15:44:32
Original
2556 people have browsed it

api comes from Turing robot. We all know that WeChat public accounts can have automatic replies. We first use a python script to write a simple automatic reply script and use the Turing robot's API.

http://www.tuling123.com/help/h_cent_webapi.jhtml?nav=doc This is the data format of the interface provided by the api. With this, it is very simple for us to develop automatic replies for WeChat public accounts. (expand by yourself).

The code is as follows:

# coding=utf-8
import json,urllib
def zidonghuifu(content):
    url='http://www.tuling123.com/openapi/api'
    data={"key": "your  key", "info": content}
    data=urllib.urlencode(data)
    html=urllib.urlopen(url,data).read()
    j=json.loads(html)
    code=j['code']
    if code == 100000:
        recontent = j['text']
    elif code == 200000:
        recontent = j['text']+j['url']
    elif code == 302000:
        recontent = j['text']+j['list'][0]['article']+j['list'][0]['detailurl']
    elif code == 308000:
        recontent = j['text']+j['list'][0]['info']+j['list'][0]['detailurl']
    else:
        recontent = '小机器人还没学会怎么回复这句话'
    return recontent
if __name__=='__main__':
    print('正在启动。。。。。')
    print('问答小程序')
    print('启动完成。。')
    while True:
        content=raw_input('问:')
        me=zidonghuifu(content)
        print(me)
Copy after login

The above is the detailed content of Using python to implement small robot automatic reply and scalable development of small robots for WeChat public accounts. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!