-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
59 lines (47 loc) · 1.62 KB
/
jarvis.py
File metadata and controls
59 lines (47 loc) · 1.62 KB
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
# jarvis.py
# Main command logic for Jarvis 2.0
import datetime
import webbrowser
import wikipedia
import pywhatkit
import pyjokes
from speak import speak
from listen import listen
def run_jarvis():
speak("Hi, I am Jarvis 2 point O, your personal assistant.")
while True:
query = listen()
if not query:
continue
if "time" in query:
time = datetime.datetime.now().strftime("%I:%M %p")
speak(f"The time is {time}")
elif "date" in query:
date = datetime.datetime.now().strftime("%d %B %Y")
speak(f"Today's date is {date}")
elif "open youtube" in query:
speak("Opening YouTube")
webbrowser.open("https://youtube.com")
elif "open google" in query:
speak("Opening Google")
webbrowser.open("https://google.com")
elif "search" in query:
speak("Searching the web")
pywhatkit.search(query.replace("search", ""))
elif "who is" in query or "what is" in query:
topic = query.replace("who is", "").replace("what is", "")
try:
info = wikipedia.summary(topic, 1)
speak(info)
except:
speak("Couldn't find details about that.")
elif "joke" in query:
joke = pyjokes.get_joke()
speak(joke)
elif "stop" in query or "exit" in query or "quit" in query:
speak("Goodbye! Have a nice day.")
break
else:
speak("Sorry, I don’t understand that command.")
if __name__ == "__main__":
run_jarvis()