Use Python to automate small robot responses to expand the small robot that develops WeChat public numbers

Source: Internet
Author: User
API to the Turing man. We all know that the public number can have automatic replies, we first write a simple auto-reply script with a Python script, using the Turing's human 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 we have to develop the public number of the automatic reply is very simple (self-expansion).

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 '] El if 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 = ' small robot has not learned how to reply to this sentence ' return recontentif __name__== ' __main__ ': print (' is starting. 。。。。 Print (' Quiz applet ') print (' Start complete. ') while True:content=raw_input (' Q: ') Me=zidonghuifu (content) print (Me) 

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.