-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__main__.py
148 lines (147 loc) · 5.81 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
try:
from __init__ import *
music_dir = 'PATH TO ANY SONG FILE'
if __name__ == "__main__":
dependencies()
animation()
wishMe()
t = 0
while True:
if t <=10:
query = takeCommand().lower()
if 'wikipedia' in query:
wikipedia_search(query)
t = t * 0
elif '.com' in query:
if 'open' in query:
query = query.replace('open', '')
webbrowser.open(query)
else:
webbrowser.open(query)
t = t * 0
elif 'play music' in query:
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))
t = t * 0
elif 'time' in query:
time = "Sir, the time is", datetime.datetime.now().strftime("%H:%M:%S")
speak(time)
t = t * 0
elif 'email to person1' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "emailid of person1"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Unable to send the email. Perhaps check your internet connection and Editions.txt file.")
t = t * 0
elif 'email to person2' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "emailid of person2"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Unable to send the email. Perhaps check your internet connection and Editions.txt file.")
t = t * 0
elif 'email to person3' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "emailid of person3"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Unable to send the email. Perhaps check your internet connection and Editions.txt file.")
t = t * 0
elif 'google' in query:
google_search(query)
t = t * 0
elif 'weather' in query:
get_weather()
t = t * 0
elif 'what is my ip' in query:
get_ip()
t = t * 0
elif 'youtube' in query:
search_youtube()
t = t * 0
elif 'news' in query:
news()
t = t * 0
elif 'joke' in query:
joke()
t = t * 0
elif 'advice' in query:
advice()
t = t * 0
elif 'exit' in query:
speak("Good bye! have a nice day!")
exit()
t = t * 0
elif 'mic' in query:
speak("Ok sir!")
unmute_mic()
t = t * 0
elif "check for updates" in query:
updates()
t = t * 0
elif "calculate" in query:
query = query.replace('calculate ', '')
calculate(query)
t = t * 0
elif 'subtitles' in query:
speak("starting subtitles...")
subtitles()
t = t * 0
else:
if query == 'none':
t = t + 1
else:
search_google(query)
else:
os.system('cls')
print("Going to sleep...")
print("To wake me up just say \"Wake up JARVIS\"")
hot_word = "wake"
with sr.Microphone() as source:
r = sr.Recognizer()
r.pause_threshold = 2
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-IN')
except sr.RequestError:
query = r.recognize_sphinx(audio, language='en-US')
query = query.lower()
if hot_word in query:
t = t * 0
speak("Waking Up...")
os.system('cls')
else:
t = t + 0
except KeyboardInterrupt:
import os
os.system("cls")
print("Assistant exited manually. Exiting JARVIS.")
exit()
except Exception as error:
import os
os.system("cls")
print("An error occured while running the code. Submitting the error to Github....")
import toke as token
tok = token.token
e = f"{error!r}: Error occured while a JARVIS user was using the bot"
import requests
import json
headers = {"Authorization" : "token {}".format(tok)}
data2 = {"title": "JARVIS Error Reporting System Reported An Error", "labels": ["Error"], "body": (e)}
url = "https://api.github.com/repos/Hashah2311/JARVIS/issues"
requests.post(url,data=json.dumps(data2),headers=headers)
exit()