-
Notifications
You must be signed in to change notification settings - Fork 185
/
main.py
377 lines (305 loc) · 13.5 KB
/
main.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
from Jarvis import JarvisAssistant
import re
import os
import random
import pprint
import datetime
import requests
import sys
import urllib.parse
import pyjokes
import time
import pyautogui
import pywhatkit
import wolframalpha
from PIL import Image
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import QTimer, QTime, QDate, Qt
from PyQt5.QtGui import QMovie
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
from Jarvis.features.gui import Ui_MainWindow
from Jarvis.config import config
obj = JarvisAssistant()
# ================================ MEMORY ===========================================================================================================
GREETINGS = ["hello jarvis", "jarvis", "wake up jarvis", "you there jarvis", "time to work jarvis", "hey jarvis",
"ok jarvis", "are you there"]
GREETINGS_RES = ["always there for you sir", "i am ready sir",
"your wish my command", "how can i help you sir?", "i am online and ready sir"]
EMAIL_DIC = {
'myself': 'atharvaaingle@gmail.com',
'my official email': 'atharvaaingle@gmail.com',
'my second email': 'atharvaaingle@gmail.com',
'my official mail': 'atharvaaingle@gmail.com',
'my second mail': 'atharvaaingle@gmail.com'
}
CALENDAR_STRS = ["what do i have", "do i have plans", "am i busy"]
# =======================================================================================================================================================
def speak(text):
obj.tts(text)
app_id = config.wolframalpha_id
def computational_intelligence(question):
try:
client = wolframalpha.Client(app_id)
answer = client.query(question)
answer = next(answer.results).text
print(answer)
return answer
except:
speak("Sorry sir I couldn't fetch your question's answer. Please try again ")
return None
def startup():
speak("Initializing Jarvis")
speak("Starting all systems applications")
speak("Installing and checking all drivers")
speak("Caliberating and examining all the core processors")
speak("Checking the internet connection")
speak("Wait a moment sir")
speak("All drivers are up and running")
speak("All systems have been activated")
speak("Now I am online")
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<=12:
speak("Good Morning")
elif hour>12 and hour<18:
speak("Good afternoon")
else:
speak("Good evening")
c_time = obj.tell_time()
speak(f"Currently it is {c_time}")
speak("I am Jarvis. Online and ready sir. Please tell me how may I help you")
def wish():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<=12:
speak("Good Morning")
elif hour>12 and hour<18:
speak("Good afternoon")
else:
speak("Good evening")
c_time = obj.tell_time()
speak(f"Currently it is {c_time}")
speak("I am Jarvis. Online and ready sir. Please tell me how may I help you")
# if __name__ == "__main__":
class MainThread(QThread):
def __init__(self):
super(MainThread, self).__init__()
def run(self):
self.TaskExecution()
def TaskExecution(self):
startup()
wish()
while True:
command = obj.mic_input()
if re.search('date', command):
date = obj.tell_me_date()
print(date)
speak(date)
elif "time" in command:
time_c = obj.tell_time()
print(time_c)
speak(f"Sir the time is {time_c}")
elif re.search('launch', command):
dict_app = {
'chrome': 'C:/Program Files/Google/Chrome/Application/chrome'
}
app = command.split(' ', 1)[1]
path = dict_app.get(app)
if path is None:
speak('Application path not found')
print('Application path not found')
else:
speak('Launching: ' + app + 'for you sir!')
obj.launch_any_app(path_of_app=path)
elif command in GREETINGS:
speak(random.choice(GREETINGS_RES))
elif re.search('open', command):
domain = command.split(' ')[-1]
open_result = obj.website_opener(domain)
speak(f'Alright sir !! Opening {domain}')
print(open_result)
elif re.search('weather', command):
city = command.split(' ')[-1]
weather_res = obj.weather(city=city)
print(weather_res)
speak(weather_res)
elif re.search('tell me about', command):
topic = command.split(' ')[-1]
if topic:
wiki_res = obj.tell_me(topic)
print(wiki_res)
speak(wiki_res)
else:
speak(
"Sorry sir. I couldn't load your query from my database. Please try again")
elif "buzzing" in command or "news" in command or "headlines" in command:
news_res = obj.news()
speak('Source: The Times Of India')
speak('Todays Headlines are..')
for index, articles in enumerate(news_res):
pprint.pprint(articles['title'])
speak(articles['title'])
if index == len(news_res)-2:
break
speak('These were the top headlines, Have a nice day Sir!!..')
elif 'search google for' in command:
obj.search_anything_google(command)
elif "play music" in command or "hit some music" in command:
music_dir = "F://Songs//Imagine_Dragons"
songs = os.listdir(music_dir)
for song in songs:
os.startfile(os.path.join(music_dir, song))
elif 'youtube' in command:
video = command.split(' ')[1]
speak(f"Okay sir, playing {video} on youtube")
pywhatkit.playonyt(video)
elif "email" in command or "send email" in command:
sender_email = config.email
sender_password = config.email_password
try:
speak("Whom do you want to email sir ?")
recipient = obj.mic_input()
receiver_email = EMAIL_DIC.get(recipient)
if receiver_email:
speak("What is the subject sir ?")
subject = obj.mic_input()
speak("What should I say?")
message = obj.mic_input()
msg = 'Subject: {}\n\n{}'.format(subject, message)
obj.send_mail(sender_email, sender_password,
receiver_email, msg)
speak("Email has been successfully sent")
time.sleep(2)
else:
speak(
"I coudn't find the requested person's email in my database. Please try again with a different name")
except:
speak("Sorry sir. Couldn't send your mail. Please try again")
elif "calculate" in command:
question = command
answer = computational_intelligence(question)
speak(answer)
elif "what is" in command or "who is" in command:
question = command
answer = computational_intelligence(question)
speak(answer)
elif "what do i have" in command or "do i have plans" or "am i busy" in command:
obj.google_calendar_events(command)
if "make a note" in command or "write this down" in command or "remember this" in command:
speak("What would you like me to write down?")
note_text = obj.mic_input()
obj.take_note(note_text)
speak("I've made a note of that")
elif "close the note" in command or "close notepad" in command:
speak("Okay sir, closing notepad")
os.system("taskkill /f /im notepad++.exe")
if "joke" in command:
joke = pyjokes.get_joke()
print(joke)
speak(joke)
elif "system" in command:
sys_info = obj.system_info()
print(sys_info)
speak(sys_info)
elif "where is" in command:
place = command.split('where is ', 1)[1]
current_loc, target_loc, distance = obj.location(place)
city = target_loc.get('city', '')
state = target_loc.get('state', '')
country = target_loc.get('country', '')
time.sleep(1)
try:
if city:
res = f"{place} is in {state} state and country {country}. It is {distance} km away from your current location"
print(res)
speak(res)
else:
res = f"{state} is a state in {country}. It is {distance} km away from your current location"
print(res)
speak(res)
except:
res = "Sorry sir, I couldn't get the co-ordinates of the location you requested. Please try again"
speak(res)
elif "ip address" in command:
ip = requests.get('https://api.ipify.org').text
print(ip)
speak(f"Your ip address is {ip}")
elif "switch the window" in command or "switch window" in command:
speak("Okay sir, Switching the window")
pyautogui.keyDown("alt")
pyautogui.press("tab")
time.sleep(1)
pyautogui.keyUp("alt")
elif "where i am" in command or "current location" in command or "where am i" in command:
try:
city, state, country = obj.my_location()
print(city, state, country)
speak(
f"You are currently in {city} city which is in {state} state and country {country}")
except Exception as e:
speak(
"Sorry sir, I coundn't fetch your current location. Please try again")
elif "take screenshot" in command or "take a screenshot" in command or "capture the screen" in command:
speak("By what name do you want to save the screenshot?")
name = obj.mic_input()
speak("Alright sir, taking the screenshot")
img = pyautogui.screenshot()
name = f"{name}.png"
img.save(name)
speak("The screenshot has been succesfully captured")
elif "show me the screenshot" in command:
try:
img = Image.open('D://JARVIS//JARVIS_2.0//' + name)
img.show(img)
speak("Here it is sir")
time.sleep(2)
except IOError:
speak("Sorry sir, I am unable to display the screenshot")
elif "hide all files" in command or "hide this folder" in command:
os.system("attrib +h /s /d")
speak("Sir, all the files in this folder are now hidden")
elif "visible" in command or "make files visible" in command:
os.system("attrib -h /s /d")
speak("Sir, all the files in this folder are now visible to everyone. I hope you are taking this decision in your own peace")
# if "calculate" in command or "what is" in command:
# query = command
# answer = computational_intelligence(query)
# speak(answer)
elif "goodbye" in command or "offline" in command or "bye" in command:
speak("Alright sir, going offline. It was nice working with you")
sys.exit()
startExecution = MainThread()
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.startTask)
self.ui.pushButton_2.clicked.connect(self.close)
def __del__(self):
sys.stdout = sys.__stdout__
# def run(self):
# self.TaskExection
def startTask(self):
self.ui.movie = QtGui.QMovie("Jarvis/utils/images/live_wallpaper.gif")
self.ui.label.setMovie(self.ui.movie)
self.ui.movie.start()
self.ui.movie = QtGui.QMovie("Jarvis/utils/images/initiating.gif")
self.ui.label_2.setMovie(self.ui.movie)
self.ui.movie.start()
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(1000)
startExecution.start()
def showTime(self):
current_time = QTime.currentTime()
current_date = QDate.currentDate()
label_time = current_time.toString('hh:mm:ss')
label_date = current_date.toString(Qt.ISODate)
self.ui.textBrowser.setText(label_date)
self.ui.textBrowser_2.setText(label_time)
app = QApplication(sys.argv)
jarvis = Main()
jarvis.show()
exit(app.exec_())