前言
现在的电脑族们,在使用电脑的过程中,常常忘记了时间的流逝,要么忙碌在电视剧的观看中,要么忙碌在工作中,要么忙碌在游戏中,往往忽视了对眼睛的正常保护,让眼睛能够在空闲的时候获得足够的休息时间。
我也是其中之一。
但当我发现自己的眼睛的疲劳程度在慢慢增加的时候,对于视力保护的需求也越来越迫切了。
于是,利用自己的小小编程技巧,利用python的简易性,实现了下面的“强制眼睛休息的脚本”,当设定的工作时间结束后,计算机的显示器会被强制关闭,如果用鼠标进行强制唤醒,显示器依然会随后快速关闭,直到设定的休息时间都过去以后,显示器才会开启。
具体实现如下
1 """ 2 count down the time to close the display 3 Create by Zhong Xiewei 4 """ 5 import time 6 import os 7 import platform 8 9 work_time = int(raw_input("Enter your work time [min]: ")) 10 break_time = int(raw_input("Enter your break time [min]: ")) 11 break_time = break_time*60 12 start = raw_input("Do you want start [y/n]: ") 13 os_str = platform.system() 14 15 work_stage = 0 16 while (start == 'y'): 17 for i in range(work_time): 18 print 'Remain ', work_time-i, 'min' 19 time.sleep(60) 20 21 # During the break time 22 # the display should always be closed 23 # if rewake by mouse, it will be closed again 24 insleep = 1 25 start_time = time.time() 26 while (insleep): 27 if os_str == "Windows": 28 # Under windows, nircmd should be installed first 29 # The usage can reference: www.nirsoft.net/utils/nircmd.html 30 os.system("nircmd.exe monitor off") 31 elif os_str == "Linux": 32 os.system("xset dpms force off") 33 end_time = time.time() 34 if end_time-start_time > break_time: 35 insleep = 0 36 37 if os_str == "Linux": 38 os.system("xset dpms force on") 39 elif os_str == "Windows": 40 os.system("nircmd.exe monitor on") 41 42 work_stage = work_stage + 1 43 print "================ Work Stage ", work_stage," ================ " 44 start = raw_input("Do you want continue [y/n]: ")