Last active
March 6, 2022 12:32
-
-
Save TruncatedDinoSour/7d22c402837a1ef2e03bc35daf297765 to your computer and use it in GitHub Desktop.
alarm.py
This file contains 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
#!/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