简体   繁体   English

如何在电脑启动时运行 python 脚本,但每天只运行一次?

[英]How to run python script on start up of pc but only once in day?

I have created a python script which do birthday wish to a person automatically when birthdate is arrive.我创建了一个 python 脚本,它会在生日到来时自动向一个人许愿。 I added this script on window start up but it run every time when i start my pc and do birthday wish to person also.我在 window 启动时添加了这个脚本,但是每次我启动我的电脑并且还对人做生日祝福时它都会运行。 I want to run that script only once a day.我只想每天运行一次该脚本。 What should i do?我应该怎么办?

Try this at the start of the file:在文件开头试试这个:

import datetime

actualday = datetime.datetime.today().day  # get the actual day 
actualmonth = datetime.datetime.today().month  # get the actual month 

bday = 1  # day of birthday
bmonth = 1  # month of birthday

if actualday == bday and actualmonth == bmonth :
    # code

it should finish the process if the dates aren't equal如果日期不相等,它应该完成该过程

You can run this program when the system boot How to start a python file while Windows starts?您可以在系统启动时运行此程序 Windows 启动时如何启动 python 文件?

And after that, you need check the time of when the system started like:之后,您需要检查系统启动的时间,例如:

import datetime
dayToday = datetime.datetime.today().day
monthToday = datetime.datetime.today().month

birthdayDay = 1
birthdayMonth = 10

if dayToday == birthdayDay and monthToday == birthdayMonth:
      print "HPBD"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM