-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfriday.py
197 lines (162 loc) · 4.95 KB
/
friday.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
import pyttsx3
import datetime
import speech_recognition as sr
import sys
import wikipedia
import smtplib
import webbrowser as wb
import os
import pyautogui
import psutil
import pyjokes
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
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"You:{query}\n")
except Exception as e:
print(e)
print("Sorry, please say that again or verify....")
return "None"
return query
def time():
Time = datetime.datetime.now().strftime("%I:%M:%S")
speak("The current time is")
speak(Time)
def date():
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
day = int(datetime.datetime.now().day)
speak("The current date is")
speak(day)
speak(month)
speak(year)
def wishme():
hour = datetime.datetime.now().hour
if hour >= 6 and hour < 12:
speak("Good Morning Ron")
elif hour >= 12 and hour < 18:
speak("Good Afternoon Ron")
elif hour >= 18 and hour < 22:
speak("Good Evening Ron")
else:
speak("Welcome Back Ron")
speak("Friday at your service")
speak("How may I help you?")
def wiki(q):
speak("Searching...")
q = q.replace("wikipedia","")
result = wikipedia.summary(q, sentences = 2)
print(result)
speak(result)
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(user, password)
server.sendmail(user, to, content)
server.close()
def Email():
try:
speak("What do you want to send, Ron?")
content = takeCommand()
to = '<insert recipient email>'
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Unable to send email")
def chrome():
speak("What should I search?")
chromepath = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
search = takeCommand().lower()
wb.get(chromepath).open_new_tab(search)
def remember():
speak('Do you want me to take a note?')
yn = takeCommand()
if 'yes' in yn:
speak('Yes Ron, What should I make note of?')
data = takeCommand()
speak('Repeating what you just said for clarification' + data)
note = open('data.txt', 'w')
note.write(data)
note.close()
elif 'no' in yn:
speak('So do you want me to tell you')
speak('the notes you asked me to take')
dec = takeCommand()
if 'yes' in dec:
note = open('data.txt', 'r')
speak('Sure sir, The notes you asked me to make are' + note.read())
elif 'no' in dec:
speak('Okay')
else:
speak('Could not get you Ron')
def screenshot():
img = pyautogui.screenshot()
img.save('C:\\Users\\Ron\\Projects\\Python\\JARVIS\\ss.png')
speak("Done!")
def cpu():
usage = str(psutil.cpu_percent())
speak("CPU usage is at" + usage)
battery = psutil.sensors_battery()
speak("Current Battery state is at")
speak(battery.percent)
def jokes():
speak(pyjokes.get_joke())
def playSongs():
song_dir = 'D:\\Music'
songs = os.listdir(song_dir)
os.startfile(os.path.join(song_dir, songs[0]))
def quit():
speak("Bella Ciao Ron!")
sys.exit()
if __name__ == "__main__":
wishme()
while True:
query = takeCommand().lower()
if "time" in query:
time()
elif "date" in query:
date()
elif "wikipedia" in query:
wiki(query)
elif 'send email' in query:
Email()
elif "chrome" in query:
chrome()
elif "where is" in query:
data = query.split(" ")
location = data[2]
speak("Hold on, I will show you where " + location + " is.")
os.system('cmd /k "start chrome https://www.google.nl/maps/place/"'+ location)
# os.system("start chrome https://www.google.nl/maps/place/" + location)
elif 'make note' in query or 'remember' in query or 'know' in query:
remember()
elif 'usage' in query or 'cpu' in query:
cpu()
elif 'joke' in query:
jokes()
elif 'songs' in query:
playSongs()
elif 'logout' in query:
os.system('shutdown -l')
elif 'shutdown' in query:
os.system('shutdown /s /t 1')
elif 'restart' in query:
os.system('shutdown /r /t 1')
elif 'screenshot' in query:
screenshot()
elif "goodbye" in query:
quit()