import telebot, asyncio, threading, datetime, time class Day: def __init__(self, date_event, month_event, time_event): if int(month_event) > int(datetime.datetime.now().strftime('%m')): #если не совпадает месяц (он больше) => отсчитывает по дням raznica_month = int(month_event) - int(datetime.datetime.now().strftime('%m')) date_now = datetime.datetime.now().strftime('%d') days_raznica = raznica_month * 30 + int(date_event) ostatok_days = days_raznica - int(date_now) self.ostatok = f'осталось времени: {ostatok_days} дней' elif int(month_event) == int(datetime.datetime.now().strftime('%m')) and int(date_event) > int(datetime.datetime.now().strftime('%d')): #если совпадает по месяцу, но не совпадает по дате => считает по дням ostatok_days = int(date_event) - int(datetime.datetime.now().strftime('%d')) self.ostatok = f'осталось времени: {ostatok_days} дней' elif int(month_event) == int(datetime.datetime.now().strftime('%m')) and int(date_event) == int(datetime.datetime.now().strftime('%d')): #если совпадает по числу и дате, но не совпадает по hours, minutes, seconds = time_event.split(':') now_hours = datetime.datetime.now().strftime('%H') now_minutes = datetime.datetime.now().strftime('%M') now_seconds = datetime.datetime.now().strftime('%S') if int(seconds) >= int(now_seconds): raznica_seconds = int(seconds) - int(now_seconds) elif int(seconds) < int(now_seconds): minutes = int(minutes)-1 seconds += 60 raznica_seconds = int(seconds) - int(now_seconds) if int(minutes) >= int(now_minutes): raznica_minutes = int(minutes) - int(now_minutes) elif int(minutes) < int(minutes) and hours >= 1: hours -= 1 minutes += 60 raznica_minutes = int(minutes) - int(now_minutes) elif int(minutes) < int(minutes) and hours < 1: self.ostatok = 'осталось времени: 00:00:00/n-------------часы-минуты-секунды' if int(hours) >= int(now_hours): raznica_hours = int(hours) - int(now_hours) self.ostatok = f'осталось времени: {raznica_hours}:{raznica_minutes}:{raznica_seconds}/n-------------часы-минуты-секунды' elif int(hours) < int(now_hours): self.ostatok = 'осталось времени: 00:00:00/n-------------часы-минуты-секунды' elif int(month_event) < int(datetime.datetime.now().strftime('%m')) or (int(month_event) == int(datetime.datetime.now().strftime('%m')) and int(date_event) < int(datetime.datetime.now().strftime('%d'))): self.ostatok = 'осталось времени: 00:00:00/n-------------часы-минуты-секунды' kollokvium = Day("26", "02", '09:19:30') Max_bond_dr = Day('11', '04', '22:00:00') # Mironov_dr = Day('10', '01', '17:00:00') learning = Day('12', '01', '09:19:30') olia_dr = Day('12', '06', '00:00:00') scdasda = Day('06', '01', '22:56:43') text = f'Мой др: {Max_bond_dr.ostatok}\nCutie`s др: {olia_dr.ostatok}\nКоллоквиум: {kollokvium.ostatok}' bot = telebot.TeleBot('6734126282:AAGGzTbXgb7CYPycn896TFYEszoqz7LYDSk') @bot.message_handler(commands=['events']) def event(message): bot.send_message(chat_id='@max_B0ndik', text = text) @bot.message_handler(commands=['new_day']) def new_day(message): new_day_send = threading.Thread(target=check_time, args=(message,)) bot.send_message(chat_id='924455959', text='Цикл запущен') new_day_send.start() def check_time(message): while True: if datetime.datetime.now().strftime('%H') == '00' and datetime.datetime.now().strftime('%A') == 'Monday': now_date = datetime.datetime.now().strftime('%d-%m-%Y') bot.send_message(chat_id='@max_B0ndik', text=f'-------------{now_date}-------------\n' f'------Начало-новой-недели------') time.sleep(4200) elif datetime.datetime.now().strftime('%H') == '00': now_date = datetime.datetime.now().strftime('%d-%m-%Y') bot.send_message(chat_id='@max_B0ndik', text=f'-------------{now_date}-------------') time.sleep(4200) else: time.sleep(600) # @bot.message_handler(commands=['start_work']) # def start(message): # bot.send_message(chat_id='@max_B0ndik', text='Бот для этого канала начал свою работу') # @bot.message_handler(commands=['id']) def ide(message): print(message.chat.id) bot.polling(none_stop=True)