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就不会出现控制台窗口了)

#
# -*- 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小脚本:定时提醒喝水 相关文章请关注php中文网!

Posted in 未分类

发表评论