-
Notifications
You must be signed in to change notification settings - Fork 0
/
aibot.py
238 lines (191 loc) · 7.6 KB
/
aibot.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
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import smtplib
from selenium import webdriver
import psutil
import pyjokes
import pyautogui
from urllib.request import urlopen
import json
import requests
import wolframalpha
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
my_wolf_id='8EW922-36E8QQYRJT'
class GUicloudbot:
def __init__(self,username,password):
self.username = username
self.password = password
self.base_url = "https://gu.icloudems.com/corecampus/student/attendance"
def login(self):
self.driver = webdriver.Chrome('./chromedriver.exe')
self.driver.get("https://gu.icloudems.com/corecampus/index.php")
self.driver.find_element_by_name('userid').send_keys(self.username)
self.driver.find_element_by_name('pass_word').send_keys(self.password)
self.driver.find_element_by_xpath("//button[contains(text(), 'LOGIN')]").click()
def attendance(self):
self.driver.find_element_by_xpath("//a[contains(@href, '/myattendance.php')]").click()
# self.driver.find_element_by_xpath('//*[@id="select2-users-rc-results"]').click()
# self.driver.find_element_by_xpath('//*[@id="select2-users-rc-result-zvgd-9"]').click()
# self.driver.find_element_by_xpath("//b[contains(text(), 'September 2020-2021')]").click()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour< 12:
speak("Good morning!")
elif hour >= 12 and hour <18:
speak("Good afternoon")
else:
speak("Good evening")
speak("Elsa is online now. How may I help you")
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
#It takes microscope input from the user and returns string output
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"User said:{query}\n")
except Exception as e:
print(e)
print("Say that again please...")
return "None"
return query
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('youremailid', 'password')
server.sendmail('youremailid',to, content)
server.close()
def cpu():
usage=str(psutil.cpu_percent())
speak('CPU is at'+usage)
print('CPU is at'+usage)
battery=psutil.sensors_battery()
speak('battery is')
speak(battery.percent )
print('battery is')
print(battery.percent)
def joke():
speak(pyjokes.get_joke())
# def screenshot():
# img=pyautogui.screenshot()
# img.save('C:/Users/Public/Pictures/screenshotAI.png')
if __name__ == "__main__":
bot = GUicloudbot('18SCSE1180008','GU@12345')
wishMe()
while True:
# if 1:
query = takeCommand().lower()
#logic for executing taska based on query
if 'wikipedia' in query:
speak('Searching wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences = 2)
speak('According to Wikipedia')
print(results)
speak(results)
elif 'open youtube' in query:
webbrowser.open("youtube.com")
elif 'open google' in query:
webbrowser.open("google.com")
elif 'open icloud' in query:
speak("opening University icloud")
bot.login()
speak("What would you like to know")
command = takeCommand()
if 'open attendance' in command:
try:
speak("opening attendance")
bot.attendance()
# speak("would you like to see today's attendance")
except Exception as e:
print(e)
speak("Sorry I'm unable to open attendance")
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Mam, the time is {strTime}")
elif 'the date' in query:
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
date = int(datetime.datetime.now().day)
speak("the current Date is")
speak(date)
speak(month)
speak(year)
elif 'open code' in query:
codePath ="C:\\Users\\varun\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
elif 'email to me' in query:
try:
speak("What shoul I say")
content = takeCommand()
to = "youremailid"
sendEmail(to,content)
speak("email has been sent")
except Exception as e:
print(e)
speak("Sorry my friend nandini. I am not able to send this email")
# elif 'search in chrome' in query:
# speak("what should i search?")
# chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' #Add the Location of the chrome browser
# r = sr.Recognizer()
# with sr.Microphone() as source:
# print('say something!')
# print('Listening...')
# audio = r.listen(source)
# print("done")
# try:
# text = r.recognize_google(audio)
# print('google think you said:\n' +text)
# webbrowser.get(chrome_path).open(text)
# except Exception as e:
# print(e)
elif 'cpu'in query:
cpu()
elif 'joke' in query:
joke()
# elif 'Screenshot' in query:
# speak("Taking a screenshot now")
# screenshot()
elif 'where is ' in query:
query=query.replace('where is','')
location=query
speak("on map "+location+'is here')
webbrowser.open_new_tab("https://www.google.com/maps/place/"+location)
elif 'news' in query:
try:
jsonObj=urlopen("http://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=32c7d7ec660744669c2719430e560f8f")
data=json.load(jsonObj)
i=1
speak('here are some top hadline from the business industry')
print('***************TOP HEADLINE***************'+'\n')
for item in data['articles']:
print(str(i)+'.'+item['title']+'\n')
print(item['description']+'\n')
speak(item['title'])
i+=1
except Exception as e:
print(str(e))
elif 'what is' in query or 'who is' in query:
client=wolframalpha.Client(my_wolf_id)
res = client.query(query)
try:
print(next(res.result).text)
speak(next(res.result).text)
except:
print("not found")
elif 'go offline' in query:
speak("ok mam shutting down the system")
quit()