python定时运行闹钟

2022年1月31日20:58:12 发表评论 3,257 views

一个小坑:处理时间判断的时候简单使用大于等于判断容易出现循环多次运行或者错过运行条件。因此引入flage

 

#-*- coding:utf-8 -*-
# projectname:编程 
# author: e语
# datetime:2021/2/9 19:50
# software: PyCharm

path = 'D:\linshi\chongfu\转移华硕\音乐\盛夏的果实.mp3'

from datetime import datetime
import os,time
boolen_run= True
print(this_time.hour,this_time.minute)
while boolen_run:
    this_time = datetime.now()
    time.sleep(5)
    if this_time.minute > 40 and this_time.hour == 4:
        os.system(path)
        boolen_run = False

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: