Skip to content

Instantly share code, notes, and snippets.

@TruncatedDinoSour
Last active March 6, 2022 12:32
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 TruncatedDinoSour/7d22c402837a1ef2e03bc35daf297765 to your computer and use it in GitHub Desktop.
Save TruncatedDinoSour/7d22c402837a1ef2e03bc35daf297765 to your computer and use it in GitHub Desktop.
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