看一个小伙伴分享的图灵机器人Python玩法,觉得挺有意思的
linux上,可以尝试更简单的方法。比如说使用curl命令 curl
"http://www.tuling123.com/openapi/api?key=申请到的key&info=聊天内容"
比如:curl "http://www.tuling123.com/openapi/api?key=fskfjaslfjals&info=hello"
#!/usr/bin/python # -- coding: utf8 -- import os import json import urllib2 class Chat(object): key = "申请的key" # turing123网站 apiurl = "http://www.tuling123.com/openapi/api?" def init(self): os.system("clear") print "尽情调教把!" print "-------------------------------" def get(self): print "> ", info = raw_input() if info == (‘q‘ or ‘exit‘ or "quit"): print "- Goodbye" return self.send(info) def send(self, info): url = self.apiurl + ‘key=‘ + self.key + ‘&‘ + ‘info=‘ + info re = urllib2.urlopen(url).read() re_dict = json.loads(re) text = re_dict[‘text‘] print ‘- ‘, text self.get() if name == "main": chat = Chat() chat.init() chat.get()
时间: 2024-10-08 20:00:19