Search code examples
pythonpython-3.xpython-2.7startupscript

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?


Solution

  • 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