Skip to content

Instantly share code, notes, and snippets.

@r3dact3d
Created March 1, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r3dact3d/519927221c0eaf266122ddf8404e1862 to your computer and use it in GitHub Desktop.
Save r3dact3d/519927221c0eaf266122ddf8404e1862 to your computer and use it in GitHub Desktop.
Simple Python Alarm Clock
#!/usr/bin/env python
# coded by Brady [r3dact3d]
# set days of week to run alarm in days list
# set song you want to wakeup to in song
# set hour and minute in h, m
# make sure mpg123 is installed on your linux
import time, datetime, os
def alarm(h, m, song):
player = 'mpg123'
while(True):
day = datetime.datetime.today().weekday()
days = [0, 1, 2, 3, 4, 5]
if(day in days):
dt = list(time.localtime(time.time()))
hour = str(dt[3])
minute = str(dt[4])
if hour == h and minute == m:
command = '%s %s' % (player, song)
process = os.popen(command)
time.sleep(0.1)
song = '/home/itsbt/wakeup.mp3'
h = '8'
m = '17'
alarm(h, m, song)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment