# # -*- coding: utf-8 -*- import subprocess import time,os def createFile(filename): if os.path.exists(filename) == False: open(filename, "a").close() if os.path.getsize(filename): pass else: f = open(filename, "a") f.write("多喝水!!") f.close() def getThisHours(): timeInfo = time.localtime() return timeInfo[3] def printTips(filename): createFile(filename); sub2 = subprocess.Popen(['notepad', filename]); lastHours = getThisHours() try: fileName = "Tips.txt" while True: nowHours = getThisHours() if(nowHours > lastHours): lastHours = nowHours printTips(fileName) time.sleep(660);#11分钟循环一次 except Exception as e: f = open("error.log", "a") f.write(str(e) + "\n") f.close()
定時提醒喝水,不用費勁的腳本添加到計劃任務了(後綴保存為.pyw的把腳本加到計劃任務了(後綴保存為.pyw就不會出現控制台窗口了)
更多python小腳本:定時提醒喝水 相關文章請關注PHP中文網!