Created
October 21, 2024 06:17
-
-
Save sphinxid/c2a15e36ff07a1b4addcc5a1cb332f8d to your computer and use it in GitHub Desktop.
A simple yet effective command-line application that implements the 20-20-20 rule for reducing eye strain while working on computers. The rule suggests that every 20 minutes, you should look at something 20 feet away for 20 seconds.
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
import time | |
import datetime | |
import os | |
import platform | |
def clear_screen(): | |
os.system('cls' if platform.system() == 'Windows' else 'clear') | |
def play_sound(repeat=10): | |
for _ in range(repeat): | |
time.sleep(0.250) | |
if platform.system() == 'Windows': | |
import winsound | |
winsound.Beep(1000, 1000) # Frequency: 1000Hz, Duration: 1000ms | |
else: | |
os.system('echo -e "\a"') # Print ASCII bell character | |
def get_next_reminder_time(): | |
now = datetime.datetime.now() | |
minutes = now.minute | |
next_20_min = (minutes // 20 + 1) * 20 | |
if next_20_min == 60: | |
next_reminder = now.replace(hour=now.hour+1, minute=0, second=0, microsecond=0) | |
else: | |
next_reminder = now.replace(minute=next_20_min, second=0, microsecond=0) | |
return next_reminder | |
def main(): | |
print("Eye Care Reminder CLI") | |
print("Press Ctrl+C to exit") | |
while True: | |
next_reminder = get_next_reminder_time() | |
while datetime.datetime.now() < next_reminder: | |
clear_screen() | |
time_left = next_reminder - datetime.datetime.now() | |
print(f"Next eye break at: {next_reminder.strftime('%H:%M:%S')}") | |
print(f"Time until next break: {time_left.seconds // 60:02d}:{time_left.seconds % 60:02d}") | |
time.sleep(1) | |
clear_screen() | |
print("Time for an eye break!") | |
print("Look at something 20 feet away for 20 seconds.") | |
play_sound() | |
for i in range(20, 0, -1): | |
print(f"Break time remaining: {i} seconds", end='\r') | |
time.sleep(1) | |
print("\nBreak finished. Keep up the good work!") | |
time.sleep(3) | |
if __name__ == "__main__": | |
try: | |
main() | |
except KeyboardInterrupt: | |
print("\nEye Care Reminder CLI closed. Take care of your eyes!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment