-
Notifications
You must be signed in to change notification settings - Fork 1
/
turing.py
38 lines (34 loc) · 892 Bytes
/
turing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import requests
import json
KEY = ''
def get_response(msg):
apiUrl = 'http://openapi.tuling123.com/openapi/api/v2'
data = {
"reqType": 0,
"perception": {
"inputText": {
"text": msg
},
"selfInfo": {
"location": {
"city": "长沙",
"province": "湖南",
"street": "麓山南路"
}
}
},
"userInfo": {
"apiKey": KEY,
"userId": "Me"
}
}
data = json.dumps(data)
try:
r = requests.post(apiUrl, data=data).json()
return r['results'][0]['values']['text']
except:
return msg
if __name__ == '__main__':
res = get_response("今天天气怎么样?")
print(res)