import requests
from aip import AipOcr
image = requests.get('https://res.pandateacher.com/python_classic.png').content
APP_ID = '16149264'
API_KEY = 'yxYg9r4OuAs4fYvfcl8tqCYd'
SECRET_KEY = 'yWg3KMds2muFsWs7MBSSFcgMQl8Wng4s'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
res = client.basicGeneral(image)
if 'words_result' in res.keys():
for item in res['words_result']:
print(item['words'])
else:
APP_ID = '11756541'
API_KEY = '2YhkLuyQGljPUYnmi1CFgxOP'
SECRET_KEY = '4rrHe2BF828bI8bQy6bLlx1MelXqa8Z7'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
res = client.basicGeneral(image)
if 'words_result' in res.keys():
for item in res['words_result']:
print(item['words'])
else:
print(res)
运行结果:
bash:74$ python ~/classroom/apps-1-id-5cd9765519bbcf0001554795/74/main.py
优美胜于丑陋
明了胜于晦涩
简洁胜于复杂
复杂胜于凌乱
扁平胜于嵌套
间隔胜于紧湊
```python
import requests, json, time, random
feature_text = '''
大家好!我是你的聊天机器人吴小枫。
我有问必答,有人会问我“今天深圳天气怎么样?”,也有人问我“你喜欢我吗?”
快来问我问题呀,欢迎来撩!
【温馨提示】如果你要删除自己输入的内容,要按两次删除,才可以删掉一个汉字奥!
(因为在计算机世界里,中文是占两个字符的!)
>'''
user1 = input(feature_text)
time.sleep(1)
userid = str(random.randint(1, 1000000000000000000000))
apikey = 'd81c0b99c260440980a140440be200ec'
#超过1w有风险,19-01-19
tulingdata1 = json.dumps({ "perception": {
"inputText": {
"text": user1
},
},
"userInfo": {
"apiKey": apikey,
"userId": userid
}
})
robot1 = requests.post('http://openapi.tuling123.com/openapi/api/v2', tulingdata1)
jsrobot1 = json.loads(robot1.text)['results'][0]['values']['text']
print(jsrobot1)
time.sleep(2)
user2 = input('''
再来问我点啥吧!我把我知道的都告诉你,嘻嘻!
>''')
tulingdata1 = json.dumps({
"perception": {
"inputText": {
"text": user2
},
},
"userInfo": {
"apiKey": apikey,
"userId": userid
}
})
robot1 = requests.post('http://openapi.tuling123.com/openapi/api/v2', tulingdata1)
jsrobot1 = json.loads(robot1.text)['results'][0]['values']['text']
time.sleep(1)
print(jsrobot1)
user3 = input('''
我有点饿了,再和你聊完最后一句,我就要下线啦!你还有什么要问我的?
>''')
tulingdata1 = json.dumps({
"perception": {
"inputText": {
"text": user3
},
},
"userInfo": {
"apiKey": apikey,
"userId": userid
}
})
robot1 = requests.post('http://openapi.tuling123.com/openapi/api/v2', tulingdata1)
jsrobot1 = json.loads(robot1.text)['results'][0]['values']['text']
time.sleep(1)
print(jsrobot1)
time.sleep(1)
print('\n我走啦,下次见!')
运行结果:
bash:78$ python ~/classroom/apps-1-id-5cd9765519bbcf0001554795/78/main.py
大家好!我是你的聊天机器人吴小枫。
我有问必答,有人会问我“今天深圳天气怎么样?”,也有人问我“你喜欢我吗?”
快来问我问题呀,欢迎来撩!
【温馨提示】如果你要删除自己输入的内容,要按两次删除,才可以删掉一个汉字奥!
(因为在计算机世界里,中文是占两个字符的!)
>
如果你什么都不说,我也不知道怎么回答你呀
再来问我点啥吧!我把我知道的都告诉你,嘻嘻!
>woshishui who am i
终于有人回了你是好人哈哈。
我有点饿了,再和你聊完最后一句,我就要下线啦!你还有什么要问我的?
>nishi who are you
就是我呀!
我走啦,下次见!
代码