What is the best way to make a function do something once a day?

Can be has simple has a 5 lines algorithm:

while True:
    # check current time
    now = datetime.datetime.now()

    # iterate over task items
    for task in scheduled:
        # check if time has passed
        if now > task['date']:
            # moves the date to how ever far away you wanted
            task['date'] = task['date'] + task['re_schedule']

Which you can use to run has many tasks has you want.

A full example would be:

import datetime

# what ever you need to do
def dothis():
    print('done')

# simple task object, dicts can do
task = {
    'date' : datetime.datetime(year=2015, month=10, day=5, hour=20, minute=2),
    're_schedule' : datetime.timedelta(days=1),
    'string' : 'some words',
    'callable' : dothis,
}

# list of stuff will do    
scheduled = []
scheduled.append(task)

def mainloop():
    from time import sleep

    while True:
        now = datetime.datetime.now()

        for task in scheduled:
            # checks if the time has passed
            if now > task['date']:

                # does its job
                print(task['string'])
                task['callable']()

                # moves the date to how ever far away you wanted
                task['date'] = task['date'] + task['re_schedule']

                # tell the os we don't wont be processing anything else
                # used to avoid using unneeded cpu.
                sleep(30)

if __name__ == '__main__':
    mainloop()

If you want to be able to shut down your computer you can just save those tasks to the disk, there's nothing much else to it.

/r/learnpython Thread