-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
188 lines (164 loc) · 5.58 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
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
import datetime
import os
import smtplib
import time as ti
import webbrowser as we
from email.message import EmailMessage
from time import sleep
import clipboard
import psutil
import pyautogui
import pyjokes
import pyttsx3
import pywhatkit
import requests
import speech_recognition as sr
from newsapi import NewsApiClient
from secret import password, senderemail
# for index, name in enumerate(sr.Microphone.list_microphone_names()):
# print("Microphone with name\"{1}\" found for `Microphone(device_index={0}`)".format(
# index, name))
def inputCommand():
# query = input()
r = sr.Recognizer()
query = ""
with sr.Microphone(device_index=2) as source:
print("Listening...")
r.pause_threshold = 1
try:
query = r.recognize_google(r.listen(source), language="en-IN")
except Exception as e:
print(e)
output("Say that again please...")
return query
def output(out):
# print(out)
engine.say(out)
engine.runAndWait()
user = "Rohit"
assistant = "Jarvis"
engine = pyttsx3.init()
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id) # Microsoft David aka male
# engine.setProperty("voice",voices[1].id) Microsoft zira aka female
output(f"Hello this is {assistant}")
def greet():
hour = datetime.datetime.now().hour
if(hour >= 6) and (hour < 12):
output(f"Good Morning {user}")
elif(hour >= 12) and (hour < 18):
output(f"Good afternoon {user}")
elif(hour >= 18) and (hour < 21):
output(f"Good Evening {user}")
output("How may i Assist you?")
def sendEmail():
email_list = {
"test": "rokano2321@to200.com"
}
try:
email = EmailMessage()
output("To whom you want to send the e-mail")
name = inputCommand().lower()
email["To"] = email_list[name]
output("What is the subject of your e-mail")
email["Subject"] = inputCommand()
email["From"] = senderemail
output("What should i Say?")
email.set_content(inputCommand())
s = smtplib.SMTP("smtp.gmail.com", 587)
s.starttls()
s.login(senderemail, password)
s.send_message(email)
s.close()
output("Email has Sent")
except Exception as e:
print(e)
output("Unable to send the Email")
def sendWhatMsg():
user_list = {
"test1": "+91 95299 16394"
}
try:
output("To whom you want to send the message")
name = inputCommand().lower()
output("What is the message")
we.open("https://web.whatsapp.com/send?phone=" +
user_list[name]+"&text="+inputCommand())
sleep(6)
pyautogui.press("enter")
output("Message sent")
except Exception as e:
print(e)
output("Unable to send the Message")
def weather():
city = "Jaipur"
res = requests.get(
f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid=<Your API Key>&units=metric").json()
temp = res["weather"][0]["description"]
temp2 = res["main"]["temp"]
output(
f"Temprature is {format(temp2)} degree Celsius \n Weather is {format(temp)}")
def news():
# https://newsapi.org/account
newsapi = NewsApiClient(api_key="<Your API Key>")
output("What topic you need the news about")
topic = inputCommand().lower()
data = newsapi.get_top_headlines(q=topic, language="en", page_size=5)
newsdata = data["articles"]
for y in newsdata:
output(y["description"])
def idea():
output("What is your idea?")
data = inputCommand().title()
output("You said me to remember this Idea: " + data)
with open("data.txt", "a", encoding="Utf-8") as r:
print(data, file=r)
greet()
while True:
query = inputCommand().lower()
if ("time" in query):
output("Current time is " + datetime.datetime.now().strftime("%I:%M"))
elif ("date" in query):
output("Current date is " + str(datetime.datetime.now().day) + " " +
str(datetime.datetime.now().month) + " " + str(datetime.datetime.now().year))
elif ("email" in query):
sendEmail()
elif ("message" in query):
sendWhatMsg()
elif("search" in query):
output("What you want to search")
we.open("https://www.google.com/search?q="+inputCommand())
elif("youtube" in query):
output("what you want to search on YouTube?")
pywhatkit.playonyt(inputCommand())
elif("weather" in query):
weather()
elif("news" in query):
news()
elif("read" in query):
output(clipboard.paste())
elif("covid" in query):
r = requests.get("https://coronavirus-19-api.herokuapp.com/all").json()
output(
f'Confirmed cases: {r["cases"]} \nDeaths: {r["deaths"]} \nRecovered {r["recovered"]}')
elif("workspace" in query):
output("Which workspace you want to work on?")
os.startfile("D:\\Work Spaces\\"+inputCommand()+".code-workspace")
elif("joke" in query):
output(pyjokes.get_joke())
elif("idea" in query):
idea()
elif("do you know" in query):
ideas = open("data.txt", "r")
output(f"You said me to remember these ideas: \n{ideas.read()}")
elif("screenshot" in query):
pyautogui.screenshot(str(ti.time()) + ".png").show()
elif ("cpu" in query):
output(f"Cpu is at {str(psutil.cpu_percent())}")
elif("offline" in query):
hour = datetime.datetime.now().hour
if(hour >= 21) and (hour < 6):
output(f"Good Night {user}! Have a nice sleep")
else:
output(f"By {user}")
quit()