1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# -*- coding: utf-8 -*- ## Copyright 2019 Trevor van Hoof and Jan Pijpers. ## Licensed under the Apache License, Version 2.0 ## Downloaded from https://janpijpers.com or https://gumroad.com/janpijpers ## See the license file attached or on https://www.janpijpers.com/script-licenses/ ''' Name: daylyRunFunction Description: Simple task scheduler to run at a daily interval. ''' import datetime import time import sched SCHEDULER = sched.scheduler(time.time,time.sleep) def repeat_action( message, timing ): ''' Do whatever magic you want to do here :D :param message: :param timing: :return: ''' print "Run forrest run!" ## Create the next scheduled event run_schedule_daily(repeat_action, *timing) def run_schedule_daily( function, hours = 0,minutes = 0, seconds = 0 ): ## what time of the day do you want to run this runTime = datetime.time(hour = hours, minute= minutes, second = seconds) nowPlus = datetime.datetime.combine(datetime.datetime.now(), runTime) if nowPlus <= datetime.datetime.now(): nowPlus = nowPlus + datetime.timedelta(days = 1) tTuple = time.mktime(nowPlus.timetuple()) SCHEDULER.enterabs(tTuple, 1, function, ("",(hours, minutes, seconds),)) print "Next run scheduled for: ", nowPlus run_schedule_daily(repeat_action, hours = 14,minutes =45, seconds = 0) SCHEDULER.run() |