python小脚本:定时提醒喝水

发布时间:2019-06-09 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了python小脚本:定时提醒喝水脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
#
# -*- 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就不会出现控制台窗口了)

脚本宝典总结

以上是脚本宝典为你收集整理的python小脚本:定时提醒喝水全部内容,希望文章能够帮你解决python小脚本:定时提醒喝水所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。