Advertisement
Tatantyler

WebBrowser Alarm Clock

Dec 31st, 2012
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. # This python script takes a length of time (expressed in hours and minutes, such as 5:31, or 5 hours and 31 minutes), and opens a new webbrowser tab or window after the specified amount of time has passed.
  2. # Made in 2012 by Tatantyler, and I claim no responsibility if the thing fails to work.
  3. # It worked for me, though.
  4.  
  5. import datetime
  6. import os
  7. import webbrowser
  8.  
  9. def setAlarm(alarm_hr, alarm_min, url):
  10.     currentTime = datetime.datetime.time(datetime.datetime.now()) #look at all those "datetime"s!
  11.     newAlarmMin = currentTime.minute+alarm_min
  12.     newAlarmHr = currentTime.hour+alarm_hr + int(newAlarmMin / 60)
  13.     newAlarmMin = newAlarmMin % 60
  14.     alarmTime = datetime.time(newAlarmHr, newAlarmMin)
  15.     oldTime = datetime.datetime.time(datetime.datetime.now())
  16.     currentTime = datetime.datetime.time(datetime.datetime.now())
  17.     print("Setting alarm for "+str(alarmTime)+" .")
  18.     while True:
  19.         currentTime = datetime.datetime.time(datetime.datetime.now())
  20.         dT = datetime.datetime.combine(datetime.date.today(), currentTime) - datetime.datetime.combine(datetime.date.today(), oldTime)
  21.         #print("dbg: "+str(dT.total_seconds()))
  22.         if (dT.total_seconds() >= 1):
  23.             oldTime = currentTime
  24.             print("Current time is: "+str(currentTime))
  25.             dT_2 = datetime.datetime.combine(datetime.date.today(), alarmTime) - datetime.datetime.combine(datetime.date.today(), currentTime)
  26.             if (dT_2.total_seconds() <= 1):
  27.                 print("Alarm is GOING OFF!")
  28.                 webbrowser.open(url, 1, True)
  29.                 return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement