Home >Backend Development >Python Tutorial >python small script: regular reminder to drink water

python small script: regular reminder to drink water

高洛峰
高洛峰Original
2017-02-16 11:19:472698browse

                 

#
# -*- 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()

Reminds you to drink water regularly, no need to add the script to the scheduled task (save the suffix as .pyw and the console window will not appear)


#
# -*- 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()


Reminder to drink water regularly, no need to add the script to the scheduled task (save the suffix as .pyw and the console window will not appear)


For more python scripts: regular reminders to drink water, please pay attention to the PHP Chinese website for related articles!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn