这个python脚本实现了一个简单的报时功能。
到休息时间,发声提醒开始休息;
到工作时间,发声提醒该工作了。
这个软件是基于windows的,如果用到linux上,则需要对发声模块进行修改 参考
import winsound # 导入此模块实现声音播放功能
import time # 导入此模块,获取当前时间
import win32com.client
speak = win32com.client.Dispatch('SAPI.SPVOICE')
rest_minute = input("请输入休息时间:")
work_minute = input("请输入工作时间:")
Hour = 23 # 下班时间,晚上11点
flag = 1
while flag:
t = time.localtime() # 当前时间的纪元值
fmt = "%H %M"
now = time.strftime(fmt, t) # 将纪元值转化为包含时、分的字符串
now = now.split(' ') #以空格切割,将时、分放入名为now的列表中
hour = now[0]
hour = int(hour)
minute = now[1]
if hour == Hour:
flag = 0
else:
if minute == rest_minute:
speak.speak("please take a break and stand up to walk around for 10 minutes")
if minute == work_minute:
speak.speak("please start to study")