Use python to implement automatic reply to small robots that can expand the development of WeChat public accounts

Source: Internet
Author: User
The Turing Robot from api. We all know that the public account can have automatic replies. We use python scripts to write a simple automatic reply script and use the Turing Robot api. The Turing Robot from api. We all know that the public account can have automatic replies. We use python scripts to write a simple automatic reply script and use the Turing Robot 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 data format, it is very easy to develop an automatic reply to the public account (self-developed ).

The code is as follows:

# Coding = utf-8import json, urllibdef 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 = 'the robot hasn't learned how to reply to this sentence 'return recontentif _ name __= = '_ main _': print ('is starting ..... ') Print ('Q & a applet') print ('Startup is complete .. ') While True: content = raw_input (' Q: ') me = zidonghuifu (content) print (me)

The preceding figure shows how to use python to automatically reply to the details of small robots with extensible public accounts. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.