Python3 Docking Chat Robot API

Source: Internet
Author: User
Tags urlencode

See http://api.qingyunke.com/for details.
Bot API Interface Description
Support Features: Weather, translation, Tibetan poetry, jokes, lyrics, calculations, domain name information/record/indexed queries, IP queries, mobile phone number attribution, Ai Chat
Interface Address: http://api.qingyunke.com/api.php?key=free&appid=0&msg= keyword
Key fixed parameter free
AppID is set to 0, which indicates smart recognition, ignoring this parameter
msg keyword, please refer to the following parameter example, the parameter can be intelligently identified, the value is urlencode processed before submitting
Return result: {"result": 0, "content": "Contents"}
Result status, 0 indicates normal, other numbers indicate error


The code below, the main need to use the knowledge point, is the JSON to dict conversion, this place is easy to ignore, resulting in the dictionary can not be removed value.
The code uses the while to do a loop, mainly consider can find robot chat. In fact the better way should be Def talk (), then use while True:talk ().
But the reason for not doing this is because you don't know how to use break in Talk () to jump out while loop ... This is for tomorrow's research.

1 #Python 3.62 #!/usr/bin/env python3 #-*-coding:utf-8-*-4 __author__='Bh8ank'5 6 7 " "8 See http://api.qingyunke.com/for details .9 Bot API Interface DescriptionTen Support Features: Weather, translation, Tibetan poetry, jokes, lyrics, calculations, domain name information/record/indexed queries, IP queries, mobile phone number attribution, Ai chat One interface address: http://api.qingyunke.com/api.php?key=free&appid=0&msg= keyword A key fixed parameter free - AppID is set to 0, which indicates smart recognition, ignoring this parameter - msg keyword, please refer to the following parameter example, the parameter can be intelligently identified, the value is UrlEncode processed before submitting the return Result: {"result": 0, "content": "Contents"} - result status, 0 indicates normal, other numbers indicate error - Content Information -  + " " - Importurllib.request + Import Time A ImportSSL at ImportJSON - Importstring -  -  -  whileTrue: -  in     #def talk (): -target = R'http://api.qingyunke.com/api.php?key=free&appid=0&msg=' to     Print("=======================") +Keyword = input ("want to talk about something:") -     ifKeyword = ="Exit": the         Print("no talking, bye.") *          Break $TMP = target +keywordPanax Notoginsengurl = urllib.parse.quote (tmp, safe=string.printable) -page =urllib.request.urlopen (URL) the     #print (URL) +  A     #url = urllib.parse.quote (tmp,safe=string.printable) the     #URL = url1.read (). Decode ("Utf-8") +html = Page.read (). Decode ("Utf-8") -     #print (HTML) $     #Print (str (page)) $  -     #page = urllib.request.urlopen (URL) -     #html = page.read () the  -     #print (HTML)Wuyires = json.loads (HTML)#JSON to Dict,json.loads is used to decode JSON data. The function returns the data type of the Python field the     #Print (res) -     #return res Wu     #res = json.loads (HTML) -     #B = json.dumps (res, ensure_ascii=false, indent=4) About     #print (b) $     #Dict_talk = json.loads (b) -     #print (Dict_talk) -     #return Dict_talk -     #A = Res A     Print(res['content']) +  the #if __name__ = = "__main__": - #While True: $ #a = talk () the #print (a[' content ') the #print (a) the #answer = Urllib.parse.unquote (a) the #answer = Json.dumps (answer, Ensure_ascii=false, indent=4) - #res = json.loads (answer) in #print (answer) the     #print ()

This robot is too moral integrity.

Python3 Docking Chat Robot API

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.