Created
December 15, 2018 21:04
-
-
Save yosefm/cb289090da199b0017ac104b337f0a43 to your computer and use it in GitHub Desktop.
My alarm clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple alarm clock, based on suggestion here: | |
https://atanok.wordpress.com/2009/10/27/amarok-kalarm-alarm-clock/ | |
Kalarm is crashy, hence Python to the rescue. | |
""" | |
import time, datetime, os | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('hour') | |
args = parser.parse_args() | |
# This case happens when called after 00:00 | |
day = datetime.date.today() # + datetime.timedelta(1) | |
alarm_time_str = str(day) + " " + args.hour | |
alarm_time_struct = time.strptime(alarm_time_str, "%Y-%m-%d %H:%M") | |
alarm_time = time.mktime(alarm_time_struct) | |
# This happens at sane hours. | |
if alarm_time <= time.time(): | |
day += datetime.timedelta(1) | |
alarm_time_str = str(day) + " " + args.hour | |
alarm_time_struct = time.strptime(alarm_time_str, "%Y-%m-%d %H:%M") | |
alarm_time = time.mktime(alarm_time_struct) | |
print "Wake you up at", alarm_time_str | |
while True: | |
now = time.time() | |
if alarm_time <= now: | |
os.system(""" | |
amarok --play | |
qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet 100 | |
""") | |
break | |
else: | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment