-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ortega.py
313 lines (283 loc) · 7.26 KB
/
Ortega.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#Author : Prabhat
#Description : This is an interactive research assistant, for computational purposes;
#Note : Although, Knowledge/Information gathering can be done using the tool, you're not suggested to totally relay on the tool (*sigh* or, you'll face some bugs and glitches) '''
import os
import time
import pyttsx3
import colorama
import wolframalpha
import speech_recognition as sr
import random
import sys
import wikipedia
from colorama import Fore,Back,Style
import base64
os.system("cls")
#initialization
r = sr.Recognizer()
engine = pyttsx3.init()
rate = engine.getProperty('rate')
engine.setProperty('rate', 150)
engine = pyttsx3.init()
os.system("cls")
engine.say("What do you want the input method to be?")
print("\n\n\nWhat do you want the input method to be?\n\n [1] Type\n [2] Speech")
engine.runAndWait()
mode = input()
def exit():
os.system('cls')
engine.say("Alright .. Exiting!")
engine.runAndWait()
def say(var):
engine.say(var)
engine.runAndWait()
def name():
say("My name is Sunday")
print("My name is Sunday.")
print("\n\t\t\t\t\t :)")
time.sleep(2)
def wait():
os.system("cls")
say("Alright .. Waiting ... Press any key to End.")
print("\n\n\nAlright \n..Waiting \n...Press any key to End")
for i in range(10):
for cursor in '\\|/-':
time.sleep(0.1)
sys.stdout.write('\r{}'.format(cursor))
sys.stdout.flush()
os.system("cls")
input("\n\n\nAlright \n..Waiting \n...Press any key to End")
def wiki():
engine.say("let me ask Wichishiki")
print("Let me ask Wichishiki :)")
engine.runAndWait()
engine.say("What do you want to know about?")
print("\n\n\n\n\t\t\t\tWhat do you want to know about?\n\n")
engine.runAndWait()
request = input("\n\t\t\t\t>?=")
response = wikipedia.summary(request)
engine.say(response)
print(response)
engine.runAndWait()
input()
def lyrics():
print("----------------------------------")
inp=input("enter name of artist and name of song separated by / : ").lower().replace(" ", '')or"edsheeran/eraser";inp=inp.split('/') if '/' in inp and inp.count('/') == 1 else 'you need to seperate the artist name from his/her title using /' if not '/' in inp or inp.count('/') > 1 else 'Invalid input....\nplease check the top comment of this code';artist,title = inp[0],inp[1]
print('Artist: {}\nTitle: {}\n{}'.format(artist.title(),title.title(),'-'*25))
import re
from urllib.request import urlopen; from html.parser import HTMLParser
link = urlopen("https://www.azlyrics.com/lyrics/{}/{}.html".format(artist,title)).read()
link = str(link)
class MyHTMLParser(HTMLParser):
def __init__(self):
super().__init__()
self.p=False
self.pbuf=[]
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
if tag=="div" and not attrs:
self.p=True
self.pbuf=[]
def handle_endtag(self, tag):
if tag=="div" and self.p:
self.p=False
print("\n".join(self.pbuf),flush=1)
self.pbuf =[]
def handle_data(self, data):
if(self.p):
data=data.replace("\\n","\n")
data=data.replace("\\","")
data = re.sub(r'\br\b', '', data)
self.pbuf.append(data.strip())
parser = MyHTMLParser()
parser.feed(link)
print('\n\nPrabhat')
def cmd():
os.system('start')
while True:
os.system("cls")
engine.say("What's you Query?")
print("\n\n\n\nWhat's your Query?: ")
engine.runAndWait()
#Setting the Input Method
if int(mode)==1:
inpt = input("")
elif int(mode)==2:
with sr.Microphone() as source:
inpt = r.listen(source)
try:
inpt = r.recognize_google(inpt)
except:
engine.say("Sorry could not recognize your voice, try again")
engine.runAndWait()
print("Sorry could not recognize your voice :/")
print("Try again")
engine.runAndWait()
with sr.Microphone() as source:
inpt = r.listen(source)
try:
inpt = r.recognize_google(inpt)
except:
engine.say("Sorry could not recognize your voice, ... Exiting")
engine.runAndWait()
print("Sorry could not recognize your voice:/")
print("Exiting")
#Computation
if inpt=="quit":
exit()
break
elif inpt=="exit":
exit()
break
elif inpt=="leave me alone":
exit()
break
elif inpt=="just shut the fuck up":
exit()
break
elif inpt=="shut up":
wait()
break
elif inpt=="close":
exit()
break
elif inpt=="how do i quit":
exit()
break
elif inpt=="what is your name":
name()
continue
elif inpt=="what's your name":
name()
continue
elif inpt=="your name":
name()
continue
elif inpt=="who are you":
name()
continue
elif inpt=="change mode":
mode()
continue
elif inpt=="start speaking":
mode()
continue
elif inpt=="change input method":
mode()
continue
elif inpt=="change input mode":
mode()
continue
elif inpt=="wait":
wait()
continue
elif inpt=="just wait for some time":
wait()
continue
elif inpt=="will you wait":
wait()
continue
elif inpt=="hold on":
wait()
continue
elif inpt=="hang on":
wait()
continue
elif inpt=="halt":
wait()
continue
elif inpt=="stay":
wait()
continue
elif inpt=="pause":
wait()
continue
elif inpt=="let me see":
wait()
continue
elif inpt=="bare with me":
wait()
continue
elif "wiki" in inpt:
wiki()
continue
elif inpt=="open wikipedia":
wiki()
continue
elif inpt=="wikipedia":
wiki()
continue
elif inpt=="search wikipedia":
wiki()
continue
elif "search wikipedia for" in inpt:
wiki(inpt.replace("search wikipedia for",""))
continue
elif inpt=="launch wikipedia":
wiki()
continue
elif inpt=="wichishiki":
wiki()
continue
elif inpt=="launch wichishiki":
wiki()
continue
elif "search wichishiki" in inpt:
wiki()
continue
elif "search wichishiki for" in inpt:
wiki(inpt.replace("search wichishiki for",""))
continue
elif inpt=="launch command prompt":
cmd()
input("")
continue
elif inpt=="launch terminal":
cmd()
input("")
continue
elif inpt=="launch shell":
cmd()
input("")
continue
elif inpt=="open terminal":
cmd()
input("")
continue
elif inpt=="open command prompt":
cmd()
input("")
continue
elif inpt=="open shell":
cmd()
input("")
continue
elif "lyrics" in inpt:
lyrics()
input("")
continue
elif inpt=="":
engine.say("Didn't recieve any input, try again")
print("Didn't recieve any input,\t:\\\n\t\tTry Again")
engine.runAndWait()
continue
#Sending the Request to Computational Service
app_id = "R5K5G6-QWQ5RT2VLA"
client = wolframalpha.Client(app_id)
rate = engine.getProperty('rate')
engine.setProperty('rate', 160)
res = client.query(inpt)
try:
try:
answer = next(res.results).text
print("You said: \n\t"+inpt+"\n\n")
except:
print("")
engine.say(answer)
print(answer)
engine.runAndWait()
except:
engine.say("I'm afraid an Error occured.")
print("I'm afraid, an Error occured.\t\t:/")
engine.runAndWait()
time.sleep(2)