forked from vishaal27/SmartAlarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_script.py
406 lines (336 loc) · 13.4 KB
/
main_script.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
import datetime
import urllib.request
from datetime import datetime as dt
from datetime import date
import calendar
from espeak import espeak
from selenium import webdriver
import email
import imaplib
import random
from espeak import espeak
import time
import math
import signal
import os
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import sys
import json
from selenium import webdriver
called=True
running=True
jokes_list=[
'0,"Yo mama so fat, I took a picture of her last Christmas and its still printing."',
'1,"What do you get when you cross a lawyer with the Godfather? An offer you cant understand."',
'2,"Yo mama so poor your family ate cereal with a fork to save milk."',
'3,"Why Does Ariel wear seashells? Because she cant fit into D-shells"',
'4,"If I could have dinner with anyone, dead or alive......I would choose alive."',
'5,"Two guys walk into a bar. The third guy ducks."',
'6,"Why cant Barbie get pregnant? Because Ken comes in a different box."',
'7,"Why was the musician arrested? He got in treble."',
'8,"Did you hear about the guy who blew his entire lottery winnings on a limousine? He had nothing left to chauffeur it."',
'9,"What do you do if a bird shits on your car? Dont ask her out again."',
'10,"He was a real gentlemen and always opened the fridge door for me"',
'11,"Telling my daugthers date that she has lice and its very contagious the closer you get to her. *Correct way to parent."',
'12,"What should you do before criticizing Pac-Man? WAKA WAKA WAKA mile in his shoes"',
'13,"Whats the difference between an illegal Mexican and an autonomous robot...? Nothing... they were both made to steal American jobs."',
'14,"What do you call a barbarian you cant see? an Invisigoth."',
'15,"How do you spell Canda? C,eh,N,eh,D,eh"',
'16,"You ever notice that the most dangerous thing about marijuana is getting caught with it?"',
'17,"What did Arnold Schwarzenegger say at the abortion clinic? Hasta last vista, baby."',
'18,"My wife is in a bad mood. I think her boyfriend forgot their anniversary. Way to go, dude. Now we all suffer..."',
'19,"My speech today will be like a mini-skirt. Long enough to cover the essentials but short enough to hold your attention!"',
'20," What does Miley Cyrus eat for Thanksgiving? Twerky! Just kidding... Drugs. She eats drugs."',
'21,"Why do you never see elephants hiding in trees? Cause they are freaking good at it"',
'22,"How did the blonde die raking leaves? She fell out of the tree."',
'23,"That guy is such a douche-bag! Is he single? Maybe I can fix him! women"',
'24,"My son just got a tattoo of a heart, a spade, a club, and a diamond, all without my permission. I guess Ill deal with him later."',
'25,"What do you call a potato in space? Spudnik"']
def check_kill_process(pstring):
for line in os.popen("ps ax | grep " + pstring + " | grep -v grep"):
fields = line.split()
pid = fields[0]
os.kill(int(pid), signal.SIGKILL)
def time_converter(time):
converted_time = datetime.datetime.fromtimestamp(
int(time)
).strftime('%I:%M %p')
return converted_time
def url_builder(city_id):
user_api = '3cey8aff6y2271cye0fbxe2806x3131cb2376xxxxx' # Obtain yours form: http://openweathermap.org/
unit = 'metric' # For Fahrenheit use imperial, for Celsius use metric, and the default is Kelvin.
api = 'http://api.openweathermap.org/data/2.5/weather?id=' # Search for your city ID here: http://bulk.openweathermap.org/sample/city.list.json.gz
full_api_url = api + str(city_id) + '&mode=json&units=' + unit + '&APPID=' + user_api
return full_api_url
def data_fetch(full_api_url):
url = urllib.request.urlopen(full_api_url)
output = url.read().decode('utf-8')
raw_api_dict = json.loads(output)
url.close()
return raw_api_dict
def data_organizer(raw_api_dict):
data = dict(
city=raw_api_dict.get('name'),
country=raw_api_dict.get('sys').get('country'),
temp=raw_api_dict.get('main').get('temp'),
temp_max=raw_api_dict.get('main').get('temp_max'),
temp_min=raw_api_dict.get('main').get('temp_min'),
humidity=raw_api_dict.get('main').get('humidity'),
pressure=raw_api_dict.get('main').get('pressure'),
sky=raw_api_dict['weather'][0]['main'],
sunrise=time_converter(raw_api_dict.get('sys').get('sunrise')),
sunset=time_converter(raw_api_dict.get('sys').get('sunset')),
wind=raw_api_dict.get('wind').get('speed'),
wind_deg=raw_api_dict.get('deg'),
dt=time_converter(raw_api_dict.get('dt')),
cloudiness=raw_api_dict.get('clouds').get('all')
)
return data
def data_output(data):
m_symbol = '\xb0' + 'C'
print('---------------------------------------')
print('Current weather in: {}, {}:'.format(data['city'], data['country']))
print(data['temp'], m_symbol, data['sky'])
print('Max: {}, Min: {}'.format(data['temp_max'], data['temp_min']))
print('')
print('Wind Speed: {}, Degree: {}'.format(data['wind'], data['wind_deg']))
print('Humidity: {}'.format(data['humidity']))
print('Cloud: {}'.format(data['cloudiness']))
print('Pressure: {}'.format(data['pressure']))
print('Sunrise at: {}'.format(data['sunrise']))
print('Sunset at: {}'.format(data['sunset']))
print('')
print('Last update from the server: {}'.format(data['dt']))
print('---------------------------------------')
#espeak.synth('Hello Vishaal.')
#time.sleep(2)
espeak.synth(' The current weather conditions in Delhi are')
time.sleep(2)
temp=data['temp']
espeak.synth('The current temperature is '+str(temp)+'degrees celsius')
time.sleep(2)
espeak.synth('The condition of the sky is '+data['sky'])
time.sleep(2)
espeak.synth('The maximum temperature in the day is '+str(data['temp_max'])+'degrees celsius')
time.sleep(2)
espeak.synth('The minimum temperature in the day is '+str(data['temp_min'])+'degrees celsius')
time.sleep(2)
espeak.synth('The relative humidity percentage is '+str(data['humidity']))
time.sleep(2)
time.sleep(2)
time.sleep(2)
if(called):
try:
alarm_time=input('What time should the alarm be set to?')
espeak.synth('Vishaal, what time should I set the alarm to?')
time.sleep(3)
alarm_tone=int(input('What is the alarm tone?'))
espeak.synth('Vishaal, what should be the alarm tone?')
time.sleep(3)
if(alarm_tone==1):
file='/home/Vishaal/Desktop/Music/better.mp3'
elif(alarm_tone==2):
file='/home/Vishaal/Desktop/Music/faded.mp3'
elif(alarm_tone==3):
file='/home/Vishaal/Desktop/Music/fight.mp3'
elif(alarm_tone==4):
file='/home/Vishaal/Desktop/Music/gone.mp3'
elif(alarm_tone==5):
file='/home/Vishaal/Desktop/Music/closer.mp3'
espeak.synth('Vishaal, alarm has been set for '+str(alarm_time))
time.sleep(3)
espeak.synth('Vishaal, alarm tone is number'+str(alarm_tone))
while(running):
current=str(dt.now())
current_time=current[11:19]
current_hours=int(current_time[:2])
current_minutes=int(current_time[3:5])
ap=''
if(current_hours==0):
ap='am'
current_hours=12
elif(current_hours>=13):
ap='pm'
current_hours-=12
else:
ap='am'
compare=str(current_hours)+str(current_minutes)+ap
awake=0
if(compare==alarm_time):
print('Get Up.It is time')
print()
os.system('vlc '+file)
x=input('Awake or ... zzz zzz zzz?')
if(x=='awake'):
check_kill_process('vlc')
awake=1
espeak.synth('Good Morning Vishaal.')
time.sleep(3)
espeak.synth('Here is a joke for you to start off your day in a cheerful mood')
time.sleep(5)
ch=random.randint(1,25)
chosen=jokes_list[ch]
if(chosen[1]=='0' or chosen[1]=='1' or chosen[1]=='2' or chosen[1]=='3' or chosen[1]=='4' or chosen[1]=='5' or chosen[1]=='6' or chosen[1]=='7' or chosen[1]=='8' or chosen[1]=='9'):
speak=chosen[4:]
else:
speak=chosen[3:]
print(speak)
espeak.synth(speak)
time.sleep(7)
espeak.synth('Haha. Funny, aint I?')
time.sleep(4)
espeak.synth('Here are the weather updates for today, Vishaal')
time.sleep(3)
data_output(data_organizer(data_fetch(url_builder(1273294))))
user="vishaal16119@iiitd.ac.in"
password=""
mail=imaplib.IMAP4_SSL('imap.gmail.com')
(retcode, capabilities)=mail.login(user,password)
mail.list()
mail.select("INBOX")
mail_from_store=[]
mail_subject_store=[]
n=0
(retcode, messages)=mail.search(None,'(UNSEEN)')
if(retcode=='OK'):
for num in messages[0].split():
n+=1
result,data=mail.fetch(num,'(RFC822)')
for r in data:
if(isinstance(r,tuple)):
o=email.message_from_bytes(r[1])
print(o['From'])
print(o['Subject'])
mail_from_store.append(o['From'])
mail_subject_store.append(o['Subject'])
print()
result,data=mail.store(num,'+FLAGS','\\Seen')
print(n)
if(n>=2):
s='Vishaal, You have '+str(n)+' unread mails Do you want me to read the names of the senders and the subjects of the mails?'
espeak.synth(s)
time.sleep(10)
elif(n==1):
s='Vishaal, You have one unread mail Do you want me to read the names of the senders and the subjects of the mails?'
espeak.synth(s)
time.sleep(10)
else:
s='Vishaal, You have no unread mails'
espeak.synth(s)
time.sleep(10)
if(n>=1):
ch=input()
if(ch=='no'):
pass
elif(ch=='yes'):
for i in range(len(mail_from_store)):
s1='You have a mail from '+str(mail_from_store[i])+' and the subject is '+str(mail_subject_store[i])
espeak.synth(s1)
time.sleep(10)
espeak.synth('Vishaal, do you want me to read the latest news?')
time.sleep(3)
choi=input()
if(choi=='yes'):
url = "http://www.timesofindia.indiatimes.com"
response =urlopen(url)
html = response.read()
pattern = re.compile('new_tops#[0-9]{1,}')
soup = BeautifulSoup(html,"html.parser")
data = soup.findAll('a',{"pg":pattern})
i=0
for a in data:
print (a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%2==0):
espeak.synth (a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
print("=======================================================================")
print('')
print("=======================================================================")
pattern2 = re.compile('new_latest#[0-9]{1,2}')
data2 = soup.findAll('a',{"pg":pattern2})
i=0
for a in data2:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%3==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
pattern_world = re.compile('World#[0-9]{1,2}')
data3= soup.findAll('a',{"pg":pattern_world})
i=0
for a in data3:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%2==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
pattern_science = re.compile('Science#[0-9]{1,2}')
data4= soup.findAll('a',{"pg":pattern_science})
i=0
for a in data4:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%2==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
pattern_education = re.compile('Education#[0-9]{1,2}')
data5= soup.findAll('a',{"pg":pattern_education})
i=0
for a in data5:
print(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
i+=1
if(i%3==0):
espeak.synth(a.text.encode('utf-8', errors = 'ignore').decode('utf-8'))
time.sleep(3)
print("===============================================================")
time.sleep(3)
driver=webdriver.Chrome("/usr/local/bin/chromedriver")
driver.get("https://www.usebackpack.com/")
driver.maximize_window()
#driver.implicitly_wait(5)
driver.find_element_by_id("loginButton").click()
username=driver.find_element_by_id("user_email")
username.send_keys("vishaal16119@iiitd.ac.in")
password=driver.find_element_by_id("user_password")
password.send_keys("")
username.submit()
deadline_elements = driver.find_elements_by_class_name('deadline-item')
deadline_counter = driver.find_elements_by_class_name('deadline-counter')
l1=len(deadline_elements)
l2=len(deadline_counter)
if(l1==1):
espeak.synth('Vishaal, you have '+str(l1)+' deadline')
time.sleep(4)
else:
espeak.synth('Vishaal, you have '+str(l1)+' deadlines')
time.sleep(4)
count = 0
for i in deadline_elements:
#deadline = i.get_attribute('innerHTML')
#rint (deadline)
#espeak.synth(deadline)
#time.sleep(5)
count += 1
for j in range(count):
i = deadline_counter[j]
d= i.get_attribute('innerHTML')
deadline=deadline_elements[j].get_attribute('innerHTML')
print(deadline)
print (d)
espeak.synth(deadline)
time.sleep(3)
espeak.synth(d)
time.sleep(5)
except KeyboardInterrupt:
running=False
print('Quitting')
print()
espeak.synth('Bye for now.')
time.sleep(2)