import re
with open('text.txt', 'r') as f:
rear = f.read()
dates = f'{rear}'
result = ''
last_day = None
for date in dates.split('\n'):
day = re.search(r'\d+-(\d+)', date).group(1)
if day != last_day:
result += '\n{}\n'.format(date)
last_day = day
else:
result += '{}\n'.format(date)
print(result)
import telebot
from telebot import types
TOKEN = "ВАШ_ТОКЕН"
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def start_comm(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
btn1 = types.KeyboardButton("say_smth")
markup.add(btn1)
mes = bot.send_message(
message.chat.id, "Выбери команду (/start, /say_smth)", reply_markup=markup)
bot.register_next_step_handler(mes, check)
@bot.message_handler(content_types=['text'])
def check(message):
x = message.text
if x == "say_smth":
command = say_hi_comm(message)
else:
command = start_comm(message)
@bot.message_handler(commands=['say_smth'])
def say_hi_comm(message):
mes = bot.send_message(message.chat.id, "Напиши что то!")
bot.register_next_step_handler(mes, func)
def func(message):
x = message.text
bot.send_message(message.chat.id, x)
bot.polling(none_stop=True)