from schedule import repeat, every, get_jobs, run_pending import time from threading import Thread from datetime import datetime as dt import csv from .config import PYTHONCHATRU, bot # https://core.telegram.org/bots/api Telegram Bot API def scheduler(): while True: run_pending() time.sleep(120) @repeat(every().day.at('06:00')) def remind(chat_to_repeat=PYTHONCHATRU, today=dt.today()): """ Remind holiday. """ with open('holidays.csv', newline='', encoding='utf-8') as holidays_file: holidays = tuple(csv.reader(holidays_file))[1:] for entry in holidays: date, holiday, description = entry date = dt.strptime(date, "%m-%d-%Y") if today.month == date.month and today.day == date.day: notification = f'🎉💻 Сегодня {holiday.upper()}!\ \n\n{description}.' if date.year != 1000: age = today.year - date.year notification += f'\n{age} годовщина' bot.send_message(chat_to_repeat, notification, parse_mode='HTML') def print_get_jobs(): all_jobs = get_jobs() text = f"├ Jobs: {str(len(all_jobs))}\ \n├ {dt.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n" text += '' + str(all_jobs) + '' return text Thread(target=scheduler).start()