Skip to content

Commit

Permalink
fix: alarm.py, initial volume issue
Browse files Browse the repository at this point in the history
  • Loading branch information
marbu committed Jan 13, 2013
1 parent 98652bb commit 302ef37
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

CMD_ALARM = "mpc clear; mpc search artist leslie | mpc add; mpc play"
CMD_VOLUME_UP = "mpc volume %d"
CMD_ALARM_INIT_VOLUME = "%s; sleep 0.1; %s" % (CMD_ALARM, CMD_VOLUME_UP)

def run_at(time_str, sched_cmd, debug=False):
"""
Expand All @@ -51,12 +52,16 @@ def sched_alarm(when_str, volume_list=None, period=1, debug=False):
# schedule alarm
time_st = time.strptime(when_str, "%H:%M")
time_obj = datetime.datetime(2012, 1, 1, time_st.tm_hour, time_st.tm_min, 0)
run_at(time_obj.strftime("%H:%M"), CMD_ALARM, debug)
if len(volume_list) == 0:
run_at(time_obj.strftime("%H:%M"), CMD_ALARM, debug)
else:
init_volume = volume_list.pop(0)
run_at(time_obj.strftime("%H:%M"), CMD_ALARM_INIT_VOLUME % init_volume, debug)
# gradually increase volume if required
time_delta = datetime.timedelta(seconds=period*60)
for volume in volume_list:
run_at(time_obj.strftime("%H:%M"), CMD_VOLUME_UP % volume, debug)
time_obj = time_obj + time_delta
run_at(time_obj.strftime("%H:%M"), CMD_VOLUME_UP % volume, debug)

def main():
op = OptionParser(usage="usage: %prog [options]")
Expand Down

0 comments on commit 302ef37

Please sign in to comment.