-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7Chats.py
744 lines (595 loc) · 21.2 KB
/
7Chats.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
import musix
import speech_recognition as sr
import pyttsx3
import pyautogui
import screen_brightness_control as sb
import psutil
import cv2
import Face_recognition
import pywhatkit
import webbrowser as web
from pytube import *
from pyautogui import *
import pyperclip
import wolframalpha
from keyboard import press_and_release
import speedtest
from geopy.distance import great_circle
from geopy.geocoders import Nominatim
import geocoder
import requests
import pyjokes
import randfacts
from time import *
import winsound
from tkinter import *
engine = pyttsx3.init()
en_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"
engine.setProperty('voice', en_voice_id)
client = wolframalpha.Client(" ") #Enter your API key of wolframalpha
def speak(audio):
print(f"{audio}")
engine.say(audio)
engine.runAndWait()
def listen():
r = sr.Recognizer()
with sr.Microphone() as source:
print("listening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing....")
query = r.recognize_google(audio, language='en-in')
print(f"Your command is {query} ")
except:
return ""
return query.lower()
MASTER = "Rahul sir"
def wishme():
press('esc')
speak("User Authentication Successful")
hr = int(datetime.datetime.now().hour)
if 0 <= hr < 12:
speak("Good Morning " + MASTER)
elif 12 <= hr < 16:
speak("Good Afternoon " + MASTER)
elif hr >= 16:
speak("Good Evening " + MASTER)
speak("How May I Help You...")
def exe():
while True:
query = listen()
if "hello" in query:
speak("Hello sir")
elif "how are you" in query:
speak("I'm fine sir. What about you?")
elif "fine" in query:
speak("Good to hear that sir")
elif "do you love me" in query:
speak("Yes sir, Of course. I Love you so much")
elif "love you" in query:
speak("I Love you too")
elif "what are you doing" in query:
speak("Nothing sir, Just setting up functions for you")
elif "need a break" in query or "sleep" in query:
speak("Ok sir, I'm going to sleep mode")
speak("If you need any help, just say hey 7Chats")
exit()
elif "volume" in query:
vol(query)
elif "brightness" in query:
brightness(query)
elif "battery" in query:
battery()
elif "current location" in query:
cl()
elif "photo" in query or "picture" in query:
photo()
elif "shutdown" in query:
shut()
elif "restart" in query:
res()
elif "capture video" in query:
video()
elif "search on youtube" in query:
query = query.replace("search", "")
query = query.replace("on youtube", "")
speak(f"Searching {query} on youtube")
youtube(query)
elif "download this video" in query:
speak("Your video is being downloaded sir...")
ytd()
elif "google search" in query:
query = query.replace("google search", "")
google(query)
elif "music" in query or "song" in query:
musix.music()
elif "what time is it" in query or "what is the time" in query:
p = strftime("%H")
r = strftime("%M")
speak("Current time is " + p + " hours " + r + " minutes")
elif "day" in query:
now = datetime.datetime.today().strftime("%A")
speak("Today is " + now)
elif "date" in query:
g = datetime.datetime.today().strftime("%d")
e = datetime.datetime.today().strftime("%m")
t = datetime.datetime.today().strftime("%Y")
speak("Today's date is " + g + " " + e + " " + t)
elif "month" in query:
e = datetime.datetime.today().strftime("%m")
speak(f"{e}")
elif "which year" in query:
t = datetime.datetime.today().strftime("%Y")
speak(f"{t}")
elif "locate" in query or "navigate" in query:
query = query.replace("locate ", "")
query = query.replace("navigate ", "")
speak(f"Locating {query} on maps")
googlemaps(query)
elif 'temperature' in query:
term = str(query)
term = term.replace("ok ", "")
term = term.replace("7Chats ", "")
term = term.replace("in ", "")
term = term.replace("what is the ", "")
term = term.replace("temperature ", "")
tempquery = str(term)
if "outside" in tempquery:
var = "Temperature in Delhi"
a = wolfram(var)
speak(f"{var} is {a} .")
else:
var1 = "Temperature in " + tempquery
ans = wolfram(var1)
speak(f"{var1} is {ans} .")
elif "chrome mode" in query:
chromemode()
elif "speed" in query:
speedTest(query)
elif "remember this" or "note" in query:
remember(query)
elif "remind me" in query:
rem()
elif "education mode" in query:
edu()
elif "youtube mode" in query:
yta()
elif "whatsapp" in query:
whatsapp()
elif "instagram" in query:
insta()
elif "news" in query:
news()
elif 'joke' in query:
jokes()
elif 'fact' in query:
facts()
elif "d drive" in query:
speak("Opening D drive")
os.startfile("D:\\")
elif "e drive" in query:
speak("Opening e drive")
os.startfile("E:\\")
elif "c drive" in query:
speak("Opening c drive")
os.startfile("C:\\")
elif "f drive" in query:
speak("Opening f drive")
os.startfile("F:\\")
elif "alarm" in query:
speak("please tell me the time to set alarm")
tt = listen()
tt = tt.replace("set alarm to", "")
tt = tt.replace(".", "")
tt = tt.upper()
alarm(tt)
elif "screenshot" in query:
speak("Capturing ScreenShot")
screenshot()
else:
speak("Unable to get it sir, please try with pre-defined commands")
def vol(query):
if "volume up" in query:
pyautogui.press("volumeup")
speak("Your volume is increased")
elif "volume down" in query:
pyautogui.press("volumedown")
speak("Your volume is decreased")
elif "mute volume" in query:
pyautogui.press("volumemute")
speak("Your volume is muted")
def brightness(query):
if "brightness to hai" in query:
sb.set_brightness(100)
speak("Your brightness is set to high")
elif "brightness to low" in query:
sb.set_brightness('-100')
speak("Your brightness is set to low")
elif "brightness to medium" in query:
sb.set_brightness(50)
speak("Your brightness is set to medium")
def battery():
battery = psutil.sensors_battery()
speak(f"Your battery percent is {battery.percent}")
if battery.power_plugged:
speak("Your PC is plugged in")
else:
speak("Your PC is unplugged")
convert(battery.secsleft)
def convert(seconds):
seconds = seconds % (24 * 3600)
hour = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
speak(f"Your pc will function upto {hour} hour {minutes} minutes")
def photo():
speak("say cheese")
camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
for i in range(3):
sleep(1)
return_value, image = camera.read()
cv2.imwrite('photos/opencv' + str(i) + '.png', image)
del camera
def video():
speak("Get ready , the video will start in a second")
vid_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
vid_cod = cv2.VideoWriter_fourcc(*'XVID')
output = cv2.VideoWriter("videos//cam_video.mp4", vid_cod, 20.0, (640, 480))
speak("press, 'g', to stop your video")
while True:
ret, frame = vid_capture.read()
cv2.imshow("My cam video", frame)
output.write(frame)
if cv2.waitKey(1) & 0XFF == ord('g'):
break
vid_capture.release()
output.release()
cv2.destroyAllWindows()
def shut():
speak("Your System will shutdown in 5 seconds")
os.system("shutdown /s /t 5")
def res():
speak("Your System will restart in 5 seconds")
os.system("shutdown /r /t 5")
def youtube(query):
result = "https://www.youtube.com/results?search_query=" + query
web.open(result)
speak("This is what i found for your search .")
pywhatkit.playonyt(query)
speak("This may also help you.")
def ytd():
sleep(5)
try:
click(x=942, y=59)
# click(x=1250, y=75)
hotkey('ctrl', 'a')
hotkey('ctrl', 'c')
link = pyperclip.paste()
Link = str(link)
YouTube(Link).streams.first().download('videos\\')
speak("Your video has been downloaded and saved to videos folder")
except:
return ""
def google(query):
speak(f"Searching {query} on google")
pywhatkit.search(query)
def maps(query):
location = query.replace("where is", "")
speak("Hold on Sir, I will show you where " + location + " is.")
web.open("https://www.google.nl/maps/place/" + location + "/&")
def wolfram(query):
api_key = "" #Enter your API key of wolframalpha
requester = wolframalpha.Client(api_key)
requested = requester.query(query)
try:
answer = next(requested.results).text
return answer
except:
speak("A string value is not answerable")
def chromemode():
speak("Chrome mode activated")
web.open(url='https://www.google.com')
speak("Tell your command sir")
while True:
try:
com = listen()
print(com)
com = com.lower()
if "incognito tab" in com:
press_and_release('ctrl + shift + n')
elif "new tab" in com:
press_and_release('ctrl + t')
elif "new window" in com:
press_and_release('ctrl + n')
elif "switch tab" in com:
press_and_release('ctrl + tab')
elif "download" in com:
press_and_release('ctrl + j')
elif "history" in com:
press_and_release('ctrl + h')
elif "close tab" in com:
press_and_release('ctrl + w')
elif "reopen closed tab" in com:
press_and_release('ctrl + shift + t')
elif "reload" in com:
press_and_release('ctrl + r')
elif "back" in com:
press_and_release('alt + left')
elif "next" in com:
press_and_release('alt + right')
elif "close window" in com:
press_and_release('alt + f4')
elif "bookmark" in com:
press_and_release('ctrl + shift + o')
elif "clear browsing data" in com:
press_and_release('ctrl + shift + delete')
elif "search" in com:
speak("what to search ?")
com = listen()
google(com)
elif "source code" in com:
press_and_release('ctrl + u')
elif "add to bookmark" in com:
press_and_release('ctrl + d')
elif "scroll down" in com:
press_and_release('space')
elif "scroll up" in com:
press_and_release('shift + space')
elif "exit chrome mode" in com:
press_and_release('alt + f4')
speak("Chrome mode exited")
break
except:
continue
def speedTest(query):
speak("Checking Your internet speed....")
speed = speedtest.Speedtest()
downloading = speed.download()
cd = int(downloading / 800000)
uploading = speed.upload()
cu = int(uploading / 800000)
if 'uploading' in query:
speak(f"Uploading speed is {cu} mbps")
elif 'downloading' in query:
speak(f"Downloading speed is {cd} mbps")
else:
speak(f"Uploading speed is {cu} mbps and Downloading speed is {cd} mbps")
def remember(rmsg):
rmsg = rmsg.replace("remember this", "")
rmsg = rmsg.replace("7Chats ", "")
remember = open('notes/remember.txt', 'w+')
remember.write(rmsg)
remember.close()
speak("ok, i remember this. ask me to remind you whenever you want .")
def rem():
reme = open("data.txt", "r")
speak("You told me to remind you this message" + reme.read())
def edu():
speak("Education mode activated!!")
while True:
sleep(2)
speak("ask your question sir..")
abc = listen()
if "exit education mode" in abc:
speak("Education mode exited")
break
abc = abc.replace("plus", "+")
abc = abc.replace("minus", "-")
abc = abc.replace("power", "^")
abc = abc.replace("by", "/")
abc = abc.replace("into", "*")
try:
wolfram_res = next(client.query(abc).results).text
speak(wolfram_res)
except:
speak("No data available")
engine.runAndWait()
def googlemaps(place):
url_place = "https://www.google.com/maps/place/" + str(place)
geolocator = Nominatim(user_agent="myGeocoder")
location = geolocator.geocode(place, addressdetails=True)
target_loc = location.latitude, location.longitude
location = location.raw['address']
target = {'city': location.get('city', ''), 'state': location.get('state', ''),
'country': location.get('country', '')}
current_loc = geocoder.ip('me')
current_latlon = current_loc.latlng
distance = str(great_circle(current_latlon, target_loc))
distance = str(distance.split(' ', 1)[0])
distance = round(float(distance), 2)
web.open(url=url_place)
speak(target)
speak(f"{place} is {distance} kilometer away from your location .")
def whatsapp():
os.startfile("") #enter your whatsapp location and make sure that you scan qrcode befor running the script
sleep(10)
speak("Tell the contact name")
name = listen()
pyautogui.click(x=124, y=166)
pyautogui.doubleClick()
press('delete')
pyautogui.typewrite(name)
sleep(1)
pyautogui.click(x=345, y=391)
speak("What do you want to do sir")
speak("Do you want me to send message, or call, or video call")
task = listen()
try:
if "message" in task:
pos = pyautogui.locateOnScreen("src/emojiB.png", confidence=.6)
x = pos[0]
y = pos[1]
pyautogui.moveTo(x + 200, y + 20, duration=.5)
pyautogui.click()
speak("Tell your message sir")
message = listen()
pyautogui.typewrite(message, interval=.01)
pyautogui.typewrite("\n", interval=.01)
elif "video" in task:
pos = pyautogui.locateOnScreen("src/video.png", confidence=.6)
x = pos[0]
y = pos[1]
pyautogui.moveTo(x, y, duration=.5)
pyautogui.click()
elif "call" in task:
pos = pyautogui.locateOnScreen("src/call.png", confidence=.9)
x = pos[0]
y = pos[1]
pyautogui.moveTo(x, y, duration=.5)
pyautogui.click()
except:
pass
def yta():
speak("Youtube mode activated")
web.open(url='https://www.youtube.com/')
speak("Tell your command sir")
while True:
try:
com = listen()
print(com)
com = com.lower()
if "pause" in com:
press_and_release('space bar')
elif "play" in com:
press_and_release('space bar')
elif "full screen" in com:
press_and_release('f')
elif "exit full screen" in com:
press_and_release('esc')
elif "theatre mode" in com:
press_and_release('t')
elif "fast forward" in com:
press_and_release('l')
elif "back forward" in com:
press_and_release('j')
elif "increase speed" in com:
press('>')
elif "decrease speed" in com:
press('<')
elif "reload" in com:
press_and_release('ctrl + r')
elif "previous" in com:
press_and_release('shift + p')
elif "next" in com:
press_and_release('shift + n')
elif "close youtube" in com:
press_and_release('alt + f4')
elif "download" in com:
ytd()
elif "history" in com:
web.open("https://www.youtube.com/feed/history")
elif "search" in com:
speak("what do you want to search for ?")
query = listen()
result = "https://www.youtube.com/results?search_query=" + query
web.open(result)
speak("This is what i found for your search .")
speak("This may help you.")
elif "open youtube" in com:
web.open(url='https://www.youtube.com/')
elif "exit youtube mode" in com:
press_and_release('alt + f4')
break
except:
continue
def insta():
web.open('https://www.instagram.com')
def news():
apikey = "4ad432c899d345f6b946ed73db668cbd"
mainurl = "https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=4ad432c899d345f6b946ed73db668cbd"
news = requests.get(mainurl).json()
article = news['articles']
newsarticle = []
for arti in article:
newsarticle.append(arti['title'])
for i in range(10):
speak(newsarticle[i])
engine.runAndWait()
def jokes():
speak(pyjokes.get_joke())
def facts():
speak(randfacts.getFact())
def alarm(timing):
altime = str(datetime.datetime.now().strptime(timing, "%I:%M %p"))
altime = altime[11:-3]
h = altime[:2]
h = int(h)
m = altime[3:5]
m = int(m)
speak(f"Done sir, alarm set at {timing}")
while True:
if h == datetime.datetime.now().hour:
if m == datetime.datetime.now().minute:
print("Alarm is running")
winsound.PlaySound('abc', winsound.SND_LOOP)
elif m < datetime.datetime.now().minute:
break
def screenshot():
try:
myScreenshot = pyautogui.screenshot()
x = str(datetime.datetime.now())
myScreenshot.save('photos/ss_'+x+'.png')
speak("screenshot is taken and saved to photos in 7Chats folder .")
except:
pass
def wifi():
os.system('cmd /c "netsh wlan show networks"')
name_of_router = input('Enter Name/SSID of the Wifi Network you wish to connect to: ')
os.system(f'''cmd /c "netsh wlan connect name={name_of_router}"''')
speak("If you're not yet connected, try connecting to a previously connected SSID again!")
def cl():
r=requests.get('https://get.geojs.io./')
ipreq=requests.get('https://get.geojs.io/v1/ip.json')
ipadd=ipreq.json()['ip']
url='https://get.geojs.io/v1/ip/geo/'+ipadd+'.json'
georeq=requests.get(url)
geodata=georeq.json()
speak(f"Latitude : {geodata['latitude']}")
speak(f"Longitude : {geodata['longitude']}")
speak(f"City : {geodata['city']}")
speak(f"Region : {geodata['region']}")
speak(f"Country : {geodata['country']}")
speak(f"Timezone : {geodata['timezone']}")
def ert():
r = requests.get('https://get.geojs.io./')
ipreq = requests.get('https://get.geojs.io/v1/ip.json')
ipadd = ipreq.json()['ip']
url = 'https://get.geojs.io/v1/ip/geo/' + ipadd + '.json'
georeq = requests.get(url)
geodata = georeq.json()
return geodata['country']
def security():
speak("Recognizing and Verifying face...Please wait...")
if Face_recognition.facerec():
wishme()
exe()
else:
speak("Face recognition failed")
speak("Enter correct password to get access")
try:
def check():
if pwd.get() == "rahul":
speak("Access granted!")
win.destroy()
wishme()
exe()
else:
speak("Incorrect password... Terminating Program...")
win.destroy()
exit()
win = Tk()
win.title('Verification')
win.geometry("800x400")
win.config(background="black")
pwd = StringVar()
msg = Label(text="Enter Password :", font=('Comic Sans MS', 16, "bold"), background="black", fg='White')
msg.place(x=100, y=100)
entry = Entry(win, textvariable=pwd, font=15, bd='3')
entry.place(x=400, y=110)
set = Button(text="Submit", command=check, font=('Comic Sans MS', 13), bg='#567', fg='White')
set.place(x=330, y=200)
win.mainloop()
except:
print()