-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathtasks.py
59 lines (48 loc) · 1.6 KB
/
tasks.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from microsoftbotframework import ReplyToActivity
import requests
import json
# https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment
"""
POST
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment
Ocp-Apim-Subscription-Key:4cfe6f744f1b486db3fa83d874bafdd9
Content-Type:application/json
Accept:application/json
"""
# https://api.korbit.co.kr/v1/ticker
def echo_response(message):
print(message)
if message["type"] == "message":
if "bitcoin" in message["text"]:
r = requests.get("https://api.korbit.co.kr/v1/ticker")
bitcoin_price = r.json()["last"]
msg = "bitcoin price is %s" % bitcoin_price
print(msg)
ReplyToActivity(fill=message,
text=msg).send()
else:
data = {
"documents": [
{
"language": "en",
"id": "1",
"text": message["text"]
}
]
}
headers = {'Ocp-Apim-Subscription-Key': '4cfe6f744f1b486db3fa83d874bafdd9',
'Content-Type': 'application/json',
'Accept': 'application/json',
}
r = requests.post("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment",
data=json.dumps(data),
headers=headers)
emo_score = r.json()["documents"][0]["score"]
msg = "emotion score is %s\n" % emo_score
if emo_score > 0.5:
msg = msg + "You look happy!"
else:
msg = msg + "You look unhappy.."
print(msg)
ReplyToActivity(fill=message,
text=msg).send()