· 4 years ago · Jul 29, 2021, 04:06 PM
1if __name__ == '__main__':
2 clear = lambda: os.system('cls')
3
4 # This Function will clean any
5 # command before execution of this python file
6 clear()
7 wishMe()
8 usrname()
9
10 while True:
11
12 query = takeCommand().lower()
13
14 # All the commands said by user will be
15 # stored here in 'query' and will be
16 # converted to lower case for easily
17 # recognition of command
18 if 'wikipedia' in query:
19 speak('Searching Wikipedia...')
20 query = query.replace("wikipedia", "")
21 results = wikipedia.summary(query, sentences = 3)
22 speak("According to Wikipedia")
23 print(results)
24 speak(results)
25
26 elif 'open youtube' in query:
27 speak("Here you go to Youtube\n")
28 webbrowser.open("youtube.com")
29
30 elif 'open google' in query:
31 speak("Here you go to Google\n")
32 webbrowser.open("google.com")
33
34 elif 'open stackoverflow' in query:
35 speak("Here you go to Stack Over flow.Happy coding")
36 webbrowser.open("stackoverflow.com")
37
38 elif 'play music' in query or "play song" in query:
39 speak("Here you go with music")
40 # music_dir = "G:\\Song"
41 music_dir = "C:\\Users\\GAURAV\\Music"
42 songs = os.listdir(music_dir)
43 print(songs)
44 random = os.startfile(os.path.join(music_dir, songs[1]))
45
46 elif 'the time' in query:
47 strTime = datetime.datetime.now().strftime("% H:% M:% S")
48 speak(f"Sir, the time is {strTime}")
49
50 elif 'open opera' in query:
51 codePath = r"C:\\Users\\GAURAV\\AppData\\Local\\Programs\\Opera\\launcher.exe"
52 os.startfile(codePath)
53
54 elif 'email to gaurav' in query:
55 try:
56 speak("What should I say?")
57 content = takeCommand()
58 to = "Receiver email address"
59 sendEmail(to, content)
60 speak("Email has been sent !")
61 except Exception as e:
62 print(e)
63 speak("I am not able to send this email")
64
65 elif 'send a mail' in query:
66 try:
67 speak("What should I say?")
68 content = takeCommand()
69 speak("whome should i send")
70 to = input()
71 sendEmail(to, content)
72 speak("Email has been sent !")
73 except Exception as e:
74 print(e)
75 speak("I am not able to send this email")
76
77 elif 'how are you' in query:
78 speak("I am fine, Thank you")
79 speak("How are you, Sir")
80
81 elif 'fine' in query or "good" in query:
82 speak("It's good to know that your fine")
83
84 elif "change my name to" in query:
85 query = query.replace("change my name to", "")
86 assname = query
87
88 elif "change name" in query:
89 speak("What would you like to call me, Sir ")
90 assname = takeCommand()
91 speak("Thanks for naming me")
92
93 elif "what's your name" in query or "What is your name" in query:
94 speak("My friends call me")
95 speak(assname)
96 print("My friends call me", assname)
97
98 elif 'exit' in query:
99 speak("Thanks for giving me your time")
100 exit()
101
102 elif "who made you" in query or "who created you" in query:
103 speak("I have been created by Gaurav.")
104
105 elif 'joke' in query:
106 speak(pyjokes.get_joke())
107
108 elif "calculate" in query:
109
110 app_id = "Wolframalpha api id"
111 client = wolframalpha.Client(app_id)
112 indx = query.lower().split().index('calculate')
113 query = query.split()[indx + 1:]
114 res = client.query(' '.join(query))
115 answer = next(res.results).text
116 print("The answer is " + answer)
117 speak("The answer is " + answer)
118
119 elif 'search' in query or 'play' in query:
120
121 query = query.replace("search", "")
122 query = query.replace("play", "")
123 webbrowser.open(query)
124
125 elif "who i am" in query:
126 speak("If you talk then definitely your human.")
127
128 elif "why you came to world" in query:
129 speak("Thanks to Gaurav. further It's a secret")
130
131 elif 'power point presentation' in query:
132 speak("opening Power Point presentation")
133 power = r"C:\\Users\\GAURAV\\Desktop\\Minor Project\\Presentation\\Voice Assistant.pptx"
134 os.startfile(power)
135
136 elif 'is love' in query:
137 speak("It is 7th sense that destroy all other senses")
138
139 elif "who are you" in query:
140 speak("I am your virtual assistant created by Gaurav")
141
142 elif 'reason for you' in query:
143 speak("I was created as a Minor project by Mister Gaurav ")
144
145 elif 'change background' in query:
146 ctypes.windll.user32.SystemParametersInfoW(20,
147 0,
148 "Location of wallpaper",
149 0)
150 speak("Background changed successfully")
151
152 elif 'open bluestack' in query:
153 appli = r"C:\\ProgramData\\BlueStacks\\Client\\Bluestacks.exe"
154 os.startfile(appli)
155
156 elif 'news' in query:
157
158 try:
159 jsonObj = urlopen('''https://newsapi.org / v1 / articles?source = the-times-of-india&sortBy = top&apiKey =\\times of India Api key\\''')
160 data = json.load(jsonObj)
161 i = 1
162
163 speak('here are some top news from the times of india')
164 print('''=============== TIMES OF INDIA ============'''+ '\n')
165
166 for item in data['articles']:
167
168 print(str(i) + '. ' + item['title'] + '\n')
169 print(item['description'] + '\n')
170 speak(str(i) + '. ' + item['title'] + '\n')
171 i += 1
172 except Exception as e:
173
174 print(str(e))
175
176
177 elif 'lock window' in query:
178 speak("locking the device")
179 ctypes.windll.user32.LockWorkStation()
180
181 elif 'shutdown system' in query:
182 speak("Hold On a Sec ! Your system is on its way to shut down")
183 subprocess.call('shutdown / p /f')
184
185 elif 'empty recycle bin' in query:
186 winshell.recycle_bin().empty(confirm = False, show_progress = False, sound = True)
187 speak("Recycle Bin Recycled")
188
189 elif "don't listen" in query or "stop listening" in query:
190 speak("for how much time you want to stop jarvis from listening commands")
191 a = int(takeCommand())
192 time.sleep(a)
193 print(a)
194
195 elif "where is" in query:
196 query = query.replace("where is", "")
197 location = query
198 speak("User asked to Locate")
199 speak(location)
200 webbrowser.open("https://www.google.nl / maps / place/" + location + "")
201
202 elif "camera" in query or "take a photo" in query:
203 ec.capture(0, "Jarvis Camera ", "img.jpg")
204
205 elif "restart" in query:
206 subprocess.call(["shutdown", "/r"])
207
208 elif "hibernate" in query or "sleep" in query:
209 speak("Hibernating")
210 subprocess.call("shutdown / h")
211
212 elif "log off" in query or "sign out" in query:
213 speak("Make sure all the application are closed before sign-out")
214 time.sleep(5)
215 subprocess.call(["shutdown", "/l"])
216
217 elif "write a note" in query:
218 speak("What should i write, sir")
219 note = takeCommand()
220 file = open('jarvis.txt', 'w')
221 speak("Sir, Should i include date and time")
222 snfm = takeCommand()
223 if 'yes' in snfm or 'sure' in snfm:
224 strTime = datetime.datetime.now().strftime("% H:% M:% S")
225 file.write(strTime)
226 file.write(" :- ")
227 file.write(note)
228 else:
229 file.write(note)
230
231 elif "show note" in query:
232 speak("Showing Notes")
233 file = open("jarvis.txt", "r")
234 print(file.read())
235 speak(file.read(6))
236
237 elif "update assistant" in query:
238 speak("After downloading file please replace this file with the downloaded one")
239 url = '# url after uploading file'
240 r = requests.get(url, stream = True)
241
242 with open("Voice.py", "wb") as Pypdf:
243
244 total_length = int(r.headers.get('content-length'))
245
246 for ch in progress.bar(r.iter_content(chunk_size = 2391975),
247 expected_size =(total_length / 1024) + 1):
248 if ch:
249 Pypdf.write(ch)
250
251 # NPPR9-FWDCX-D2C8J-H872K-2YT43
252 elif "jarvis" in query:
253
254 wishMe()
255 speak("Jarvis 1 point o in your service Mister")
256 speak(assname)
257
258 elif "weather" in query:
259
260 # Google Open weather website
261 # to get API of Open weather
262 api_key = "Api key"
263 base_url = "http://api.openweathermap.org / data / 2.5 / weather?"
264 speak(" City name ")
265 print("City name : ")
266 city_name = takeCommand()
267 complete_url = base_url + "appid =" + api_key + "&q =" + city_name
268 response = requests.get(complete_url)
269 x = response.json()
270
271 if x["cod"] != "404":
272 y = x["main"]
273 current_temperature = y["temp"]
274 current_pressure = y["pressure"]
275 current_humidiy = y["humidity"]
276 z = x["weather"]
277 weather_description = z[0]["description"]
278 print(" Temperature (in kelvin unit) = " +str(current_temperature)+"\n atmospheric pressure (in hPa unit) ="+str(current_pressure) +"\n humidity (in percentage) = " +str(current_humidiy) +"\n description = " +str(weather_description))
279
280 else:
281 speak(" City Not Found ")
282
283 elif "send message " in query:
284 # You need to create an account on Twilio to use this service
285 account_sid = 'Account Sid key'
286 auth_token = 'Auth token'
287 client = Client(account_sid, auth_token)
288
289 message = client.messages \
290 .create(
291 body = takeCommand(),
292 from_='Sender No',
293 to ='Receiver No'
294 )
295
296 print(message.sid)
297
298 elif "wikipedia" in query:
299 webbrowser.open("wikipedia.com")
300
301 elif "Good Morning" in query:
302 speak("A warm" +query)
303 speak("How are you Mister")
304 speak(assname)
305
306 # most asked question from google Assistant
307 elif "will you be my gf" in query or "will you be my bf" in query:
308 speak("I'm not sure about, may be you should give me some time")
309
310 elif "how are you" in query:
311 speak("I'm fine, glad you me that")
312
313 elif "i love you" in query:
314 speak("It's hard to understand")
315
316 elif "what is" in query or "who is" in query:
317
318 # Use the same API key
319 # that we have generated earlier
320 client = wolframalpha.Client("API_ID")
321 res = client.query(query)
322
323 try:
324 print (next(res.results).text)
325 speak (next(res.results).text)
326 except StopIteration:
327 print ("No results")
328
329 # elif "" in query:
330 # Command go here
331 # For adding more commands
332