Skip to content

Instantly share code, notes, and snippets.

@TruncatedDinosour
Last active March 6, 2022 12:32
Embed
What would you like to do?
alarm.py
#!/usr/bin/env python3
import sys
from time import sleep
# python3 -m pip install --user beepy
from beepy import beep # type: ignore
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <time in minutes>")
sys.exit(1)
try:
minutes = int(sys.argv[1])
except ValueError:
print("Invalid numeric value (%s) for minutes" % sys.argv[1])
print("Should be an integer >= 0")
sys.exit(1)
if minutes < 0:
print("Invalid value for minutes, should be >0")
sys.exit(1)
try:
if minutes > 0:
print(f"Sleeping for {minutes} {'minute' if minutes == 1 else 'minutes'}")
sleep(minutes * 60)
print("Wake up")
while True:
beep(1)
sleep(0.5)
except KeyboardInterrupt:
print("Interrupted by user")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment