Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
4
Indexable
Never
import telebot
from bs4 import BeautifulSoup
import requests

bot = telebot.TeleBot('6546216275:AAHOQc25wIDab_mIbQ2gjEK03WSzHp3lAwc')

@bot.message_handler(commands=['start'])
def main(message):
    bot.send_message(message.chat.id, "Сливаешь каточки? Тима постоянно руинит? Тогда тебе к сюда!")


@bot.message_handler(commands=['dota'])
def main(message):
    bot.send_message(message.chat.id, "Какие персонажи тебя интересуют?")


@bot.message_handler(commands=['Lion'])
def main(message):
    headers = {
        "Accept": "*/*",
        "User-Agent": "Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"
    }
    req = requests.get('https://dota2protracker.com/', headers=headers)
    src = req.text
    soup = BeautifulSoup(src, "lxml")
    matches = soup.find('div', {'class': 'scroll-area'}).find_all('tr')

    for m in matches:
        hero_name_elem = m.find('td', {'class': 'td-hero-pic'})
        if hero_name_elem:
            hero_name = hero_name_elem.find('a')
        else:
            continue

        if hero_name.text.strip() != 'Lion':
            continue

        winrate_elem = m.find('td', {'class': 'td-winrate'})
        winrate = winrate_elem.find('span').text.strip() if winrate_elem else 'N/A'

        matches_played_elem = m.find('td', {'class': 'td-matches'})
        matches_played = matches_played_elem.find('div',
                                                  {'class': 'perc-wr'}).text.strip() if matches_played_elem else 'N/A'

        bot.send_message(message.chat.id, hero_name.text.strip())
        bot.send_message(message.chat.id, winrate)
        bot.send_message(message.chat.id, matches_played)


bot.polling(none_stop=True)