-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwolframAlphaOhbot.py
115 lines (73 loc) · 2.58 KB
/
wolframAlphaOhbot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
##Example of ohbot intergrated with wolfram alpha and wikipedia web service
import wolframalpha
from ohbotWin import ohbot
from random import *
import threading
import wikipedia
wiki = False
## please replace ???? with your own wolframalpha client id.
wolfclient = wolframalpha.Client('??????-??????????')
connectingPhrases = ['Let me think', 'Just a second', 'give me a moment', 'thats an easy one','thats tricky','i know this one','let me get you an answer']
ohbot.reset()
def handleInput():
while True:
text = input("Question:\n")
ohbot.say(text)
ohbot.eyeColour(10,5,0,True)
randIndex = randrange(0,len(connectingPhrases))
choice = connectingPhrases[randIndex]
ohbot.move(ohbot.HEADTURN,5)
ohbot.move(ohbot.EYETILT,7)
ohbot.move(ohbot.HEADNOD,9)
ohbot.say(choice)
try:
res = wolfclient.query(text)
ans = next(res.results).text
ans = ans.replace("|",".")
ohbot.say(ans)
ohbot.eyeColour(0,10,0,True)
except:
print('Answer not available')
ohbot.say("Answer not available")
ohbot.eyeColour(10,0,0,True)
ohbot.move(ohbot.HEADTURN,5)
def handleInputWiki():
while True:
text = input("Define:\n")
ohbot.say(text)
ohbot.eyeColour(10,5,0,True)
randIndex = randrange(0,len(connectingPhrases))
choice = connectingPhrases[randIndex]
ohbot.move(ohbot.HEADTURN,5)
ohbot.move(ohbot.EYETILT,7)
ohbot.move(ohbot.HEADNOD,9)
ohbot.say(choice)
try:
res = wikipedia.summary(text)
ohbot.say(res)
ohbot.eyeColour(0,10,0,True)
except:
print('Answer not available')
ohbot.say("Answer not available")
ohbot.eyeColour(10,0,0,True)
ohbot.move(ohbot.HEADTURN,5)
def moveLoop():
while True:
ohbot.move(randint(0,2),randint(0,9))
ohbot.wait(randint(0,3))
def blinking():
while True:
ohbot.move(ohbot.LIDBLINK,0,10)
ohbot.wait(random()/3)
ohbot.move(ohbot.LIDBLINK,10,10)
ohbot.wait(randint(0,6))
t = threading.Thread(target=moveLoop, args=())
if wiki:
t2 = threading.Thread(target=handleInputWiki, args=())
else:
t2 = threading.Thread(target=handleInput, args=())
t3 = threading.Thread(target=blinking, args=())
t.start()
t2.start()
t3.start()
ohbot.say("Hello ohbot here, please type in a question")