forked from zwmccall/Python_Projects-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebsiteAlarm.py
56 lines (47 loc) · 1.52 KB
/
WebsiteAlarm.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
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# authors: Shivam Sharma / Pierre Bouillon
""" `WebsiteAlarm.py` asks for a website and an alarm to be
set, then open the browser when time reach the alarm
"""
import time
from time import sleep
import webbrowser
from webbrowser import open
class BrowserAlarm(object):
""" Check an alarm every .5 seconds
Open a web browser when ringing
Attributes:
- _alarm : (int) time provided by user
- _url : (int) url to open on ringing
"""
def __init__(self, url, alarm):
self._alarm = alarm
self._url = url
self._check_param()
self._warn_launch()
def _check_param(self):
""" Check if the URL is correct
exit with an error message in the URL is incorrect
"""
if 'http' not in self._url \
or 'https' not in self._url:
exit('Bad URL')
def _warn_launch(self):
""" Prints the alarm time
"""
msg ='Now running until {}'
print (msg.format(self._alarm))
def loop(self):
""" Main loop
Check the time ever .5 second (to avoid skipping
a second)
Open the url on a webbrowser times are matching
"""
while time.strftime("%I:%M:%S") != self._alarm :
sleep(.5)
print('Now launching browser ...')
open(self._url)
if __name__ == '__main__':
alarm = BrowserAlarm('https://github.com', '06:48:00')
alarm.loop()