Last active
May 14, 2022 08:32
-
-
Save dmp40/532a6d0334ce955be859837f42d6626c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# пример отсюда https://www.youtube.com/watch?v=HodO2eBEz_8&t=165s | |
# Гоша Сударь TelegramBot на Python | |
# повторная регистрация не проходить возраст не записывается. | |
# версия от 13 мая 22 делаю по аналогии с ботом в ManyChat | |
import telebot | |
import time | |
from telebot import types #для работы клавиатуры | |
from datetime import datetime | |
import gspread | |
from telebot.types import ReplyKeyboardMarkup | |
name = ' ' | |
age = 0 | |
num_test = 1 | |
googlesheet_id = '1szSGwpZ2A' | |
token = '53101697' | |
bot = telebot.TeleBot(token) | |
@bot.message_handler( commands = [ 'start', 'help' ]) | |
def send_welcome(message ): | |
bot.reply_to(message, 'Привет, здесь можно пройти тест на гибкость. ') | |
bot.reply_to(message, 'Давайте, знакомиться ') | |
@bot.message_handler(func=lambda m: True) | |
def echo_all(message): | |
if message.text == 'Привет': | |
bot.reply_to(message, 'И вам привет!') | |
elif message.text == '?': | |
bot.reply_to(message,"Надо пройти регистрацию. Как вас зовут?") | |
bot.register_next_step_handler(message, reg_name) | |
print('стоп') | |
def reg_name(message): | |
global name | |
name = message.text | |
print(name) | |
bot.send_message(message.chat.id, 'Очень приятно,' +' '+ name) | |
time.sleep(2) | |
bot.send_message(message.chat.id, 'А сколько вам лет?') | |
bot.register_next_step_handler(message, reg_age) | |
def reg_age(message): | |
global age | |
print(age) | |
#age = message.text | |
while age == 0: | |
try: | |
age = int(message.text) | |
except Exception: | |
bot.send_message(message.chat.id, 'Вводите цифрами') | |
break | |
if age == 0: | |
bot.register_next_step_handler(message, reg_age) | |
else: | |
# открываем Google таблицу и добавляем запись | |
print(age) | |
print('Добавляю в таблицу') | |
gc = gspread.service_account('service_account.json') | |
sht1 = gc.open_by_key('1szSGwpZ2AxB1_8suohXo7zcMYkG8FUWENLrxboRdGdg') # ключ из ссылки таблицы | |
today = datetime.now().strftime('%d-%m-%Y * %H:%M') | |
time_current = datetime.today().strftime('%H:%M') | |
print(today, time_current) | |
sht1.sheet1.append_row([today, time_current, name, age]) | |
keyboard = types.InlineKeyboardMarkup() | |
key_yes = types.InlineKeyboardButton(text='Да', callback_data= 'yes') | |
#keyboard.add(key_yes) | |
key_no = types.InlineKeyboardButton(text='Нет', callback_data='no') | |
keyboard.add(key_yes,key_no) | |
bot.send_message(message.chat.id, 'Готовы пройти тест на гибкость и растяжку мышц?', reply_markup=keyboard) | |
keyboard2 = types.InlineKeyboardMarkup() | |
item = types.InlineKeyboardButton(text = 'Далее', callback_data = 'Dalee') | |
keyboard2.add(item) | |
bot.send_message(call.message.chat.id, 'Для начала нажмите Далее', reply_markup = keyboard2) | |
@bot.callback_query_handler(func=lambda call: True) | |
def callback_worker(call): | |
if call.data == 'yes': | |
print('Вывести видео') | |
elif call.data == 'Dalee': | |
print('Нажато Далее') | |
else: | |
bot.send_message(call.message.chat.id, 'https://www.youtube.com/watch?v=wDtqkdamyBM') | |
# with open('тест_5.mp4', 'rb') as f: | |
# image_bytes = f.read() | |
# bot.send_video(call.message.chat.id, image_bytes) | |
def video_test(call): | |
global num_test | |
if num_test == 1: | |
with open('тест_5.mp4', 'rb') as f: | |
image_bytes = f.read() | |
num_test = num_test +1 | |
bot.send_video(call.message.chat.id, image_bytes) | |
print(age) | |
# пример отсюда https://ru.stackoverflow.com/questions/1322519/telegram-bot-%D0%BA%D0%B0%D0%BA-%D0%BE%D1%82%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D1%82%D1%8C-%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8E-gif | |
with open('тест_5.mp4', 'rb') as f: | |
image_bytes = f.read() | |
@bot.message_handler(commands=['test']) | |
def welcome_message(message): | |
bot.send_message(message.chat.id, 'Привет, вот тест на гибкость плечевого пояса. ') | |
print('start0') | |
#time.sleep(2) | |
#bot.send_message(message.chat.id, 'Загружаю...') | |
#bot.send_video(message.chat.id, image_bytes, timeout=300 ) #заработало | |
bot.send_video(message.chat.id, image_bytes, timeout=900) | |
print('start') | |
bot.polling(none_stop=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment