Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
2
Indexable
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=["Vengeful_Spirit", "Abaddon", "Alchemist", "Ancient_Apparition", "Anti-Mage", "Arc_Warden", "Axe", "Bane", "Batrider", "Beastmaster", "Bloodseeker", "Bounty_Hunter", "Brewmaster", "Bristleback", "Broodmother", "Centaur_Warrunner", "Chaos_Knight", "Chen", "Clinkz", "Clockwerk", "Crystal_Maiden", "Dark_Seer", "Dark_Willow", "Dawnbreaker", "Dazzle", "Death_Prophet", "Disruptor", "Doom", "Dragon_Knight", "Drow_Ranger", "Earth_Spirit", "Earthshaker", "Elder_Titan", "Ember_Spirit", "Enchantress", "Enigma", "Faceless_Void", "Grimstroke", "Gyrocopter", "Hoodwink", "Huskar", "Invoker", "Io", "Jakiro", "Juggernaut", "Keeper_of_the_Light", "Kunkka", "Legion_Commander", "Leshrac", "Lich", "Lifestealer", "Lina", "Lion", "Lone_Druid", "Luna", "Lycan", "Magnus", "Marci", "Mars", "Medusa", "Meepo", "Mirana", "Monkey_King", "Morphling", "Muerta", "Naga_Siren", "Nature's_Prophet", "Necrophos", "Night_Stalker", "Nyx_Assassin", "Ogre_Magi", "Omniknight", "Oracle", "Outworld_Destroyer", "Pangolier", "Phantom_Assassin", "Phantom_Lancer", "Phoenix", "Primal_Beast", "Puck", "Pudge", "Pugna", "Queen_of_Pain", "Razor", "Riki", "Rubick", "Sand_King", "Shadow_Demon", "Shadow_Fiend", "Shadow_Shaman", "Silencer", "Skywrath_Mage", "Slardar", "Slark", "Snapfire", "Sniper", "Spectre", "Spirit_Breaker", "Storm_Spirit", "Sven", "Techies", "Templar_Assassin", "Terrorblade", "Tidehunter", "Timbersaw", "Tinker", "Tiny", "Treant_Protector", "Troll_Warlord", "Tusk", "Underlord", "Undying", "Ursa", "Venomancer", "Viper", "Visage", "Void_Spirit", "Warlock", "Weaver", "Windranger", "Winter_Wyvern", "Witch_Doctor", "Wraith_King", "Zeus"])
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')
    command1 = message.text.replace('/', '')  # убираем символ
    command = command1.replace('_', ' ')  # заменяем
    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() != command:
            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)