-
Notifications
You must be signed in to change notification settings - Fork 3
/
Features.py
305 lines (244 loc) · 8.21 KB
/
Features.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
## Import Packages
import pyttsx3 ## Python Text to Speech
import webbrowser ##For Open Web Pages
import wikipedia ## For Getting Summary From Wikipedia While Google Search
from pytube import YouTube ## For Downloading Videos from Youtube
from time import sleep ## For Sleep Program
import pyperclip ## For Copy Paste
import os ## For OS System Calls
import speedtest ## For Checking Internet Speed
import webbrowser
import pyautogui
from time import sleep
import keyboard
import AppOpener
import keyboard
import re as Regex
import requests
import openai
from Game import Play
# =============================================
## Changing Assistant Sound to Female
Engine = pyttsx3.init()
Voices=Engine.getProperty("voices");
Engine.setProperty("voice",Voices[1].id);
Engine.setProperty('rate',170)
## Speak Function For Command
def Speak(Command):
Engine.say(Command);
Engine.runAndWait();
def YoutubeSearch(Query):
Result="https://www.youtube.com/results?search_query="+Query;
webbrowser.open(Result);
Speak("Showing Results I Found on Youtube");
# YoutubeSearch("ARY News");
def GoogleSearch(Query):
Res="https://www.google.com/search?q="+Query
webbrowser.open(Res)
Search=wikipedia.summary(Query,2);
Speak(Search)
# GoogleSearch("Hello World");
def DownloadVideo():
sleep(5)
Value=pyperclip.paste()
Link=str(Value);
def Download(Link):
try:
URL=YouTube(Link);
Speak("Initiating The Download");
print("--> Initiating The Download : ",Link)
Video=URL.streams.filter(res="720p").first();
Video.download('C:\\Users\\Zubair Gujjar\\Downloads\\Video')
Speak("Video Has Been Downloaded and Saved to Video Folder in Downlods Folder");
os.startfile('C:\\Users\\Zubair Gujjar\\Downloads\\Video');
except:
Speak("Error Occoured, Youtube Video URL or May Be a Network Issue");
Download(Link);
# DownloadVideo();
def SpeedTest():
try:
Speak("Please Hold On, Checking Internet Speed")
Speed = speedtest.Speedtest()
DownloadSpeed = Speed.download()/1024/1024
String ="Your Download Speed Is : "+"{:.2f}".format(DownloadSpeed)+ "MB";
print(f"--> {String}")
Speak(String);
UploadSpeed = Speed.upload()/1024/1024
String ="Your Upload Speed Is : "+"{:.2f}".format(UploadSpeed)+ "MB";
print(f"--> {String}")
Speak(String);
except:
Speak("Time Out, Please Try Again");
# SpeedTest()
def Calculator(Exp):
try:
Ans=eval(Exp)
print(f"--> Answer of Expression '{Exp}' is = {Ans}")
Speak(f"Answer of {Exp} is {Ans}")
except:
Speak("Expression Error, Your Expression is Faulty")
# Calculator("3 * 2")
def WhatsappMessage(Name,Message):
try :
webbrowser.open("https://web.whatsapp.com/")
sleep(20)
pyautogui.click(x=289, y=185);
sleep(3)
keyboard.write(Name)
sleep(3)
pyautogui.click(x=205, y=288)
sleep(2)
pyautogui.click(x=1035, y=705)
sleep(2)
keyboard.write(Message)
keyboard.press("enter")
Speak(f"Message Sent Successfully to {Name}")
except:
Speak("Unable to Send Message ")
# WhatsappMessage("Papa Jan","Hello World !!");
def RunProgramme(App):
try:
AppOpener.run(App)
except:
Speak("OOPS Error Occured While Opening Programme")
# RunProgramme("weather")
def ShowWindow(Arg):
try:
keyboard.press_and_release(f'windows + {int(Arg)}')
except:
Speak("Currently Unable to Open Window")
# ShowWindow(2)
def CloseWindow():
try:
keyboard.press_and_release('alt+f4')
except:
Speak("Currently Unable to Close Window")
# CloseWindow()
def MinimizeWindow():
try:
keyboard.press_and_release(f'windows+m')
except:
Speak("Currently Unable to Minimize Window")
# MinimizeWindow()
def MaximizeWindow():
try:
keyboard.press_and_release(f'windows+{keyboard.KEY_UP}')
except:
Speak("Currently Unable to Maximize Window")
# MaximizeWindow()
def MuteAudio():
try:
pyautogui.press('volumemute')
except:
Speak("Currently Unable to Mute Audio")
# MuteAudio()
def IncreaseAudio(Text):
Speak("Increasing Volume")
try:
NumArray = Regex.findall(r'\d+', Text)
Ind=0;
while Ind<int(NumArray[0]):
pyautogui.press('volumeup')
Ind+=1;
except:
while Ind<5:
pyautogui.press('volumeup')
Ind+=1
# IncreaseAudio()
def DecreaseAudio(Text):
Speak("Decreasing Volume")
try:
NumArray = Regex.findall(r'\d+', Text)
Ind=0;
while Ind<int(NumArray[0]):
pyautogui.press('volumedown')
Ind+=1;
except:
Ind=0;
while Ind<5:
pyautogui.press('volumedown')
Ind+=1;
# DecreaseAudio()
def TurnOnWiFi():
import ctypes
commands = u'/k netsh interface set interface "Wi-Fi" enabled && exit'
ctypes.windll.shell32.ShellExecuteW(None,u"runas",u"cmd.exe",commands,None,1)
# TurnOnWiFi()
def TurnOffWiFi():
import ctypes
commands = u'/k netsh interface set interface "Wi-Fi" disabled && exit'
ctypes.windll.shell32.ShellExecuteW(None,u"runas",u"cmd.exe",commands,None,1)
# TurnOffWiFi()
def TellJoke():
try:
URL="https://icanhazdadjoke.com/";
Req=requests.get(URL,headers={"Accept":"application/json"}).json()
print(Req['joke'])
Speak(Req['joke'])
except:
Speak("Can't Tell You a Joke Right Now, May be a Network Issue")
# TellJoke()
def Respond():
Speak(f"Hey, {os.getlogin()}, Is There Anything That I can Do For You")
# Respond()
def Google(Query):
Res="https://www.google.com/search?q="+Query
webbrowser.open(Res)
# Google()
def ScreenShot():
from PIL import Image
from datetime import datetime
myScreenshot = pyautogui.screenshot()
Time = datetime.now().strftime("%Y-%m-%d-%H%M%S")
Path=r'C:\Users\Zubair Gujjar\Pictures\Saved Pictures\{}.jpg'.format(Time)
myScreenshot.save(Path)
Speak("Captured Screenshot and Have Been Saved to Pictures Folder")
Image.open(Path).show()
# ScreenShot()
def CurrentTime():
from datetime import datetime
import pytz
Zone = pytz.timezone("Asia/Karachi")
Time = datetime.now(Zone)
Current = Time.strftime("%I:%M:%S %p")
print(f"--> The Current Time Is : {Current}")
Speak(Current)
# CurrentTime()
def WriteNote(Message):
try:
from datetime import datetime
import pytz
Zone = pytz.timezone("Asia/Karachi")
Time = datetime.now(Zone)
Current = Time.strftime("%I-%M-%S %p")
FileName=str(Time).replace(":","-") + "-Note.txt"
with open(FileName,"w") as File:
File.write(Message)
Path1=r'D:\Semester #5\(AI) Artificial Intelligence Lab\AI Lab Project\Virtual Assistant\{}'.format(FileName)
Path2=r'C:\Users\Zubair Gujjar\Documents\{}'.format(FileName)
import shutil
shutil.move(Path1,Path2)
Speak("Note Successfully Added and Have Been Saved to Documents Folder")
except:
Speak("Unable to Add Note For You")
# WriteNote("Hello World")
def Weather():
import json
from urllib.request import urlopen
Entry=json.load(urlopen("http://ipinfo.io/json"))
Query=Entry['city']
Data=requests.get(f'https://api.weatherapi.com/v1/forecast.json?key=e3e5a6e2101943eb83550323222106&q=${Query}&aqi=no').json()
Statement=f"Currently It's {Data['current']['temp_c']} Degree Centigrade, With {Data['current']['condition']['text']} Condition In {Data['location']['name']} With Wind Speed Of {Data['current']['wind_kph']} Kilometers Per Hour";
print(f"--> Temp : {Data['current']['temp_c']} Degree Centigrade")
Speak(Statement)
return ""
# Weather()
def QuestionAnswer(Question):
openai.api_key = "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"
response = openai.Completion.create(engine="text-davinci-003",prompt=Question)
print(f"--> Answer : {response.choices[0].text.strip()}")
Speak(response.choices[0].text.strip())
# QuestionAnswer("Who Creaed God ?")
def Games():
Play()
# Games()