Last active
February 29, 2016 19:39
-
-
Save timkofu/7eeef9dcad0c699db45e to your computer and use it in GitHub Desktop.
Code to help with sticking to the 20-20-20 rule.
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
# Combat Computer Vision Syndrome using the 20-20-20 rule | |
# Every 20 minutes, spend 20 seconds looking at something 20 feet away, minimum. | |
# https://www.vsp.com/computer-vision-syndrome.html | |
# @timkofu, 2016 | |
import subprocess | |
import time | |
import sys | |
import os | |
if __name__ == "__main__": | |
try: | |
mpg123 = subprocess.check_output( | |
"which mpg123", shell=True | |
).strip().decode("utf-8") | |
notification_sound = os.path.join( | |
os.path.dirname(os.path.abspath(__file__)), "notification.mp3" | |
) | |
with open(os.devnull, "w") as trashcan: | |
notify = lambda: subprocess.call( | |
[mpg123, "-q", notification_sound], | |
stdout=trashcan, | |
stderr=subprocess.STDOUT | |
) | |
# Here we go: | |
notify() | |
while True: | |
time.sleep(60*20) # 20 minutes | |
notify() | |
for _ in range(20): | |
time.sleep(1) | |
notify() | |
except KeyboardInterrupt: | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment