import telebot
from telebot import types
import bs4
from bs4 import BeautifulSoup
import requests
def getanekdot():
z=''
s=requests.get('http://anekdotme.ru/random')
b=bs4.BeautifulSoup(s.text, "html.parser")
p=b.select('.anekdot_text')
for x in p:
s=(x.getText().strip())
z=z+s+'\n\n'
return s
@bot.message_handler(content_types='text')
def handle_text(message):
msg=message.text
msg=msg.lower()
if message.text == 'анекдот':
bot.send_message(message.chat.id, getanekdot())
@bot.message_handler(content_types=['video'])
def video_maker(message):
chat_id = message.chat.id
file_info = bot.get_file(message.video.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'test/' + file_info.file_path
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "Я сохранил ваше видео!"