-
Notifications
You must be signed in to change notification settings - Fork 0
/
App_M-One_Interface_Typing - v1.0.py
345 lines (292 loc) Β· 11.7 KB
/
App_M-One_Interface_Typing - v1.0.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
# AI Personal Assistant M-One β Version 1.0 β Interface Typing
# Built by Mahdi Rabiee
# Created: Sunday, May 8, 2022
from translate import Translator
import webbrowser
import wikipedia
import requests
import pyqrcode
import datetime
import pyttsx3
import urllib
import time
import os
# Configure speaking
engine = pyttsx3.init('sapi5')
engine.setProperty("rate", 140)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
# Function " Speaking or playing audio "
def speak(text):
engine.say(text)
engine.runAndWait()
# Login and welcome message
print('Welcome to the personal assistant M-One \n')
speak("Welcome to the personal assistant M-One")
# Variable " User name "
userName = "Mahdi"
# Function " Say hello to the user "
def sayHello():
speak(f"Hi {userName}")
sayHello()
# Help message
speak("How can i help?")
# Function " Get commands from the user "
def takeCommand():
query = input(">>> ")
try:
print(f"User said: {query}\n")
except:
pass
return query
# Loop " Command line "
while True:
query = takeCommand().lower()
if query == 0:
continue
# Function " Check the internet connection "
def connection():
checkConnection = 1
try:
requests.get('http://google.com')
except:
checkConnection += 1
# Declare the connection status
if checkConnection == 1:
pass
elif checkConnection == 2:
speak("Check your connection.")
if 'help' in query or '?' in query:
print("<<< Help for use commands >>> \n")
speak("Help for use commands")
print("'>>>': Means typing commands")
print("'hi / hello'")
print("'who am i'")
print("'hey m-one / m-one'")
print("'good morning'")
print("'good afternoon'")
print("'good evening'")
print("'i am fine / i am good / i am great'")
print("'thanks'")
print("'thank you / thank'")
print("'what your name'")
print("'how are you'")
print("'who are you'")
print("'who made you'")
print("'time / what time is it'")
print("'date'")
print("'what day is today'")
print("'convert text to speech / text to speech'")
print("'version / ver'")
print("'stop'")
print("'shutdown pc / shutdown'")
print("'restart'")
print("'qrcode / qr / qr code'")
print("'wikipedia / searching wikipedia'")
print("'open website / open web / open url'")
print("'open google'")
print("'open gmail'")
print("'open notepad'")
print("'open cmd'")
print("'new folder'")
print("'del folder'")
print("'del file'")
print("'download'")
print("'translate / translator'")
print("'password wifi / pass wifi / show password wifi'")
print("'my ip'")
print("\n")
continue
if 'hi' in query or 'hello' in query:
print(f"Hey {userName}, how are you?")
speak(f"Hey {userName}, how are you?")
continue
if 'who am i' in query:
print(f"Admin ({userName})")
speak(f"Admin ({userName})")
continue
if 'hey m-one' in query or 'm-one' in query:
print(f"Hello {userName}, How can i help?")
speak(f"Hello {userName}, How can i help?")
continue
if 'good morning' in query:
print("Good morning too")
speak("Good morning too")
continue
if 'good afternoon' in query:
print("Good afternoon too")
speak("Good afternoon too")
continue
if 'good evening' in query:
print("Good evening too")
speak("Good evening too")
continue
if 'i am fine' in query or 'i am good' in query or 'i am great' in query:
print("I am glad you're fine π")
speak("I am glad you're fine")
continue
if 'thanks' in query:
print(f"Thank you, {userName} π")
speak(f"Thank you, {userName}")
continue
if 'thank you' in query or 'thank' in query:
print("Just doing my job π")
speak("Just doing my job")
continue
if 'what your name' in query:
print('My name is " M-One "')
speak('My name is " M-One "')
continue
if 'how are you' in query:
print("I'm Good Thanks π")
speak("I'm Good Thanks")
continue
if 'who are you' in query:
print('I`m your personal assistant M-One. I work for minor tasks such as opening websites such as Google, announcing time and date, converting text to audio, creating qrcode, extracting information from wikipedia, downloading photos, etc., translating texts, displaying stored WiFi passwords, displaying public IP You, shut down the computer, create a folder and delete it, the ability to delete files on the computer, and all other features.')
speak('I`m your personal assistant M-One. I work for minor tasks such as opening websites such as Google, announcing time and date, converting text to audio, creating qrcode, extracting information from wikipedia, downloading photos, etc., translating texts, displaying stored WiFi passwords, displaying public IP You, shut down the computer, create a folder and delete it, the ability to delete files on the computer, and all other features.')
continue
if 'who made you' in query:
print("I was built by Mahdi")
speak("I was built by Mahdi")
continue
if 'time' in query or 'what time is it' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
print(f"The time is {strTime}")
speak(f"The time is {strTime}")
continue
if 'date' in query:
strDate = datetime.datetime.today().strftime("%Y/%d/%m")
print(f"The date is {strDate}")
speak(f"The date is {strDate}")
continue
if 'what day is today' in query:
strDateToday = datetime.datetime.today().strftime("%A")
print(f"Today is {strDateToday}")
speak(f"Today is {strDateToday}")
continue
if 'convert text to speech' in query or 'text to speech' in query:
speak("Enter Text To Convert")
enterTextConvert = input("Enter Text To Convert: ")
enterTextConvertName = input("File Name: ")
engine.save_to_file(enterTextConvert, f'{enterTextConvertName}.mp3')
engine.runAndWait()
print("Text to speech converter was successfully completed. The MP3 file is stored on the current path.")
speak("Text to speech converter was successfully completed. The MP3 file is stored on the current path.")
continue
if 'version' in query or 'ver' in query:
print("Version 1.0")
speak("Version 1.0")
continue
if 'stop' in query or 'exit' in query or 'esc' in query:
print("Your personal assistant M-One is shutting down, Good bye.")
speak("Your personal assistant M-One is shutting down, Good bye.")
break
if 'shutdown pc' in query or 'shutdown' in query:
shutdown = input("Do you want to shutdown your computer (yes / no): ")
if shutdown == 'yes':
speak("Your computer turns off in a few moments...")
os.system("shutdown /s /t 1")
else:
print("Shutdown is not requested.")
speak("Shutdown is not requested.")
continue
if 'restart' in query:
speak("Restart")
os.system("cls")
time.sleep(1.2)
print('Welcome your AI personal assistant M-One \n')
speak("Welcome your AI personal assistant M-One")
continue
if 'qrcode' in query or 'qr' in query or 'qr code' in query:
speak("Enter the text to generate a QR code")
enterText = input("Enter Text: ")
createQR = pyqrcode.create(enterText)
createQR.svg("qrcode.svg", scale= 6)
getCwd = os.getcwd()
print(f"QR code created successfully. \nLocation saved files: '{getCwd}'")
speak("QR code created successfully.")
continue
if 'wikipedia' in query or 'searching wikipedia' in query:
connection()
speak("Searching Wikipedia")
enterText = input("Searching Wikipedia: ")
result = wikipedia.summary(enterText)
speak("Search result")
print(result)
speak(result)
continue
if 'open website' in query or 'open web' in query or 'open url' in query:
addressWeb = input("Address Website (URL): ")
speak(f"Open website {addressWeb}")
webbrowser.open_new_tab(addressWeb)
continue
if 'open google' in query:
webbrowser.open_new_tab("https://www.google.com")
print("Google is open now")
speak("Google is open now")
continue
if 'open gmail' in query:
webbrowser.open_new_tab("gmail.com")
speak("Google Mail open now")
continue
if 'open notepad' in query:
print("Notepad is open now")
speak("Notepad is open now")
os.system("Notepad")
continue
if 'open cmd' in query:
print("Cmd is open now")
speak("Cmd is open now")
os.system("cmd.exe")
continue
if 'new folder' in query:
pathFolder = input("Path Folder: ")
nameFolder = input("Name Folder: ")
os.mkdir(pathFolder + nameFolder)
print(f"'{nameFolder}' folder was created successfully.")
speak(f"{nameFolder} folder was created successfully.")
continue
if 'del folder' in query:
pathFolder = input("Path Folder: ")
nameFolder = input("Name Folder: ")
os.removedirs(pathFolder + nameFolder)
print(f"'{nameFolder}' folder was successfully removed.")
speak(f"{nameFolder} folder was successfully removed.")
continue
if 'del file' in query:
pathFile = input("Path File: ")
nameFile = input("Name & Format File: ")
os.remove(pathFile + nameFile)
print(f"'{nameFile}' file was successfully removed.")
speak(f"{nameFile} file was successfully removed.")
continue
if 'download' in query:
connection()
fileUrl = input("URL: ")
fileNameFormat = input("File Name & Format: ")
print("Waiting...")
urllib.request.urlretrieve(fileUrl, fileNameFormat)
print(f"'{fileNameFormat}' file downloaded successfully.")
speak(f"'{fileNameFormat}' file downloaded successfully.")
continue
if 'translate' in query or 'translator' in query:
connection()
enterTextTranslate = input("Enter Text: ")
translateLang = Translator(from_lang='en', to_lang='persian')
translate = translateLang.translate(enterTextTranslate)
print(translate)
continue
if 'password wifi' in query or 'pass wifi' in query or 'show password wifi' in query:
os.system("netsh wlan export profile key=clear")
getCwd = os.getcwd()
print(f"WiFi password is stored in the XML file. To view the password, open the XML file and see the 'keyMaterial' tag. \nLocation of saved files: '{getCwd}'")
continue
if 'my ip' in query:
connection()
requestPublic = requests.get('https://get.geojs.io/v1/ip.json')
myIpPublic = requestPublic.json()['ip']
print("Your public IP:", myIpPublic)
continue
else:
print("Not Found.")
speak("Not Found.")