简体   繁体   中英

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. 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. 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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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