-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.py
71 lines (63 loc) · 1.97 KB
/
start.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
60
61
62
63
64
65
66
67
68
69
70
71
from wit import Wit
from datetime import date
import time
import random
entity_list={'paul\'s birthday' : date(1996,11,8),
'defense' : date(2020,9,1)}
greetings={1 : "hey" ,
2 : "hi" ,
3 : "hello" ,
4 : "how can I help you" ,
5 : "Yo" ,
6 : "😕" ,
7 : "🖖" ,
8 : "👋" ,
9 : "👊" ,
10 : "welcome to reality, were nothing ever happens as planned.The more you live, the more you realise that life is nothing other than pain, suffering and loneliness" }
def get_date(entity='') :
entit=entity.lower()
print(entit+" is on the "+entity_list[entit].isoformat()) if entit in entity_list else print('I don\'t know')
def get_time(entity='') :
print('Sorry, I don\'t know')
def get_current_time() :
print(time.strftime("%H:%M"))
def get_location(entity='') :
print('sorry, I don\'t know')
intent_list={'get_date' : get_date,
'get_time' : get_time,
'get_current_time' : get_current_time,
'get_location' : get_location,}
def greet() :
random.seed()
i=random.randint(1,10)
print(greetings[i])
def handle_intents(resp) :
intent=resp['intents'][0]['name']
entities=resp['entities']
if intent in intent_list :
if entities :
for entity in entities :
for i in entities[entity] :
intent_list[intent](i['value'])
else :
intent_list[intent]
else :
print("I dont know")
client=Wit(access_token='JO6XKLQFUXGIKTM6LVU4XMZM3RQQS74A')
sms=str(input("hi there\n>"))
i=0
while True:
resp=client.message(msg=sms)
if 'wit$greetings' in resp['traits'] :
greet()
i=1
if resp['intents'] :
handle_intents(resp)
i=1
if 'wit$bye' in resp['traits'] :
print('bye')
i=1
break
if i==0 :
print("Sorry I don\'t understand")
sms=str(input(">"))