Добавлена возможность установки таймера

main
Dmitry Kovtun 2024-05-23 13:48:00 +03:00
parent 9d2d66a40f
commit 9710fd0df9
1 changed files with 21 additions and 13 deletions

View File

@ -223,6 +223,8 @@ if __name__ == "__main__":
PATH_SCV = "List_groups.csv"
SEARCH_FREE_SAMBA = "dc=lenenergo,dc=ru"
TIME_RUN = "13:43"
def run_script():
logging.info("> Run script <")
@ -254,16 +256,22 @@ if __name__ == "__main__":
logging.error(ex)
scheduler = sched.scheduler(time.time, time.sleep)
# задание времени выполнения функции
event_time = datetime.datetime.now().replace(hour=12, minute=36, second=0, microsecond=0)
# добавление задания в планировщик
scheduler.enterabs(event_time.timestamp(), 1, run_script, ())
# запуск планировщика
while True:
try:
scheduler.run()
time.sleep(0.5)
except KeyboardInterrupt:
print("exit")
break
def time_run(hour:int, minuts:int):
if isinstance(hour, int) and isinstance(minuts, int) is False:
raise "Type error hour and minute is not int !!!!!"
try:
logging.info(f" -> The launch will be every day in {hour}:{minuts} <-")
while True:
time.sleep(1)
z = time.localtime()
if z.tm_hour == hour and z.tm_min == minuts and z.tm_sec == 0:
logging.info(f"-> Run time {hour}:{minuts}")
run_script()
logging.info(f" -> The launch will be every day in {hour}:{minuts} <-")
except KeyboardInterrupt:
logging.warning("ctr+c")
exit()
time_data = TIME_RUN.split(":")
time_run(int(time_data[0]), int(time_data[1]))