Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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.
- # Made in 2012 by Tatantyler, and I claim no responsibility if the thing fails to work.
- # It worked for me, though.
- import datetime
- import os
- import webbrowser
- def setAlarm(alarm_hr, alarm_min, url):
- currentTime = datetime.datetime.time(datetime.datetime.now()) #look at all those "datetime"s!
- newAlarmMin = currentTime.minute+alarm_min
- newAlarmHr = currentTime.hour+alarm_hr + int(newAlarmMin / 60)
- newAlarmMin = newAlarmMin % 60
- alarmTime = datetime.time(newAlarmHr, newAlarmMin)
- oldTime = datetime.datetime.time(datetime.datetime.now())
- currentTime = datetime.datetime.time(datetime.datetime.now())
- print("Setting alarm for "+str(alarmTime)+" .")
- while True:
- currentTime = datetime.datetime.time(datetime.datetime.now())
- dT = datetime.datetime.combine(datetime.date.today(), currentTime) - datetime.datetime.combine(datetime.date.today(), oldTime)
- #print("dbg: "+str(dT.total_seconds()))
- if (dT.total_seconds() >= 1):
- oldTime = currentTime
- print("Current time is: "+str(currentTime))
- dT_2 = datetime.datetime.combine(datetime.date.today(), alarmTime) - datetime.datetime.combine(datetime.date.today(), currentTime)
- if (dT_2.total_seconds() <= 1):
- print("Alarm is GOING OFF!")
- webbrowser.open(url, 1, True)
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement