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!