通過呼叫小黃雞介面進行自聊天

2021-08-10 00:23:26 字數 1751 閱讀 4134

importurllib2

importjson

importsys

reload(sys)

sys.setdefaultencoding('utf-8')

defxiaohuangji(content):

url =r''+content #

請求的**

reson = urllib2.urlopen(url) #

得到http

的返回碼

reson = json.loads(reson.read()) #

把json

格式字串解碼轉換成

python

物件

returnreson['text'].encode('utf-8')#

將字典中的

'text'

鍵的值列印

file ='c:\\users\\administrator\\pycharmprojects\\q\\tt.txt'fout = open(file,'a')

fout.write("您已開始進入與小黃雞的交談\n"+'\n')

content="我很喜歡和你聊天"fout.write(content+'\n')

response = xiaohuangji(content)

fout.write(response.encode(encoding='utf-8')+'\n')

foriinxrange(18): #自己與自己進行對話18句

response = xiaohuangji(str(response))

print(type(response),response.decode('utf-8'))

fout.write(response +'\n')

fout.write('\n')

通過反射呼叫介面的方法

之前使用公司的框架,業務使用到的一般就是action serviceimpl business模式,其中業務邏輯主要寫在businsess中,這個裡面有一段和常用但是一直不知道原理是什麼,就是下面這段 user user this.getdao getbean userdao.class selec...

通過openresty進行根據介面名稱進行介面限流

411 2020 07 01 10 46 03 curl o openresty openssl111 1.1.1d 1.x86 64.rpm 413 2020 07 01 10 46 52 curl o openresty resty 1.15.8.3 1.x86 64.rpm 415 2020 ...

通過介面來對專案進行分層(模擬)

首先定義乙個介面 public inte ce dao在新建乙個類來通過介面來對資料庫進行操作 public class log1 向資料庫中新增資料 public void adddate 向資料庫中刪除資料 public void deletedate 向資料庫中修改資料 public void...