Не работает Python код (BOT Telegram)
Нет никаких ошибок, просто как мне кажется он не берет значения заданные реальным временем config.py. В боте выдает Error 403 на команду /coefficient
csfail.py
from selenium import webdriver # используется для открытия браузера
from bs4 import BeautifulSoup # используется для парсинга с html кода нужный мне class
import requests
from time import sleep
from math import sqrt
import config
def check_start(value):
text = 'start in'
if value.text == text:
result = True
else:
result = False
return result
def calculate(price_value, skin, peoples):
a = peoples + skin
b = price_value - a
if b < 0:
b *= -1
c = sqrt(sqrt(b)) - 0.1
if (price_value % 1) % 0.1 == 0:
v = c - ((price_value % 1) % 0.1)
else:
if price_value % 1 > 0.5:
v = c - ((price_value % 1))
else:
v = c - ((price_value % 1) * 2)
if v > 2.1:
v -= 0.25
else:
v -= 0.15
return v
chromedriver = config.driver # путь к драйверу chrome
options = webdriver.ChromeOptions()
options.binary_location = config.binary_location
options.add_argument('headless') # для скрытого запуска браузера
options.add_argument('disable-gpu') # для отключения GPU в использовании драйверного браузера
browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=options) # запускаем браузер
browser.get(config.page_link) # открываем сайт
def prestart():
response = requests.get(config.page_link)
html = response.content
config.status_code = response.status_code
def start():
history_html = browser.page_source # получаем код страницы
soup = BeautifulSoup(history_html, 'lxml') # делаем soup
start = soup.find(class_ = 'xhistory__content ng-star-inserted')
price_value = soup.find(class_ = 'statistics__value symbol_usd')
peoples = soup.find(class_ = 'statistics__value')
skin = soup.find_all(class_ = 'statistics__value')
################################################################################
for value in skins:
if value != price and value != peoples:
config.skin = value.text
################################################################################
config.price_value = price.text.replace(',' , '')
################################################################################
if check_start(start) == True:
config.is_start = True
else:
config.is_start = False
################################################################################
config.peoples = peoples.text
################################################################################
if float(config.price_value) > 0:
config.coef = round(calculate(float(config.price_value), float(config.skin), float(config.peoples)), 3)
config.py
BOT_API = 'мой ключ' #АПИ ключ бота
page_link = 'https://cs.fail/'
binary_location = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' #путь до хрома
driver = r'C:\\Program Files\\Google\Chrome\\Application\\chromedriver.exe' #Путь до драйвера хрома
status_code = 1
is_start = False
skin = 1
price_value = 1
peoples = 1
coef = 1.000
bot.py
import telebot
from telebot import types
import config
from time import sleep
import csfail
import datetime
bot = telebot.TeleBot(config.BOT_API)
@bot.message_handler(commands=['start'])
def handle_start(message):
username = message.from_user.first_name
hello = 'Привет, ' + username + ', я бот, прогнозирующий коэффициент на CSGO.FAIL'
bot.send_message(message.chat.id, hello)
def send_coeff(id):
now = datetime.datetime.now()
if config.coef > 10:
coef = 'коэффициент будет +- 10' + '\n' + str(config.coef) + '(HASH)'
elif config.coef < 1:
coef = 'Краш очень близко!' + '\n' + str(config.coef) + '(HASH)'
else:
coef = 'Минимальный коэффициент = ' + str(config.coef)
if config.is_start == True:
text =now.strftime("%d-%m-%Y %H:%M") +'\n'+ '----------------------------------'+ '\n' + 'Игра началась'+ '\n'+'Кол-во игроков: ' + config.peoples + '\n' + 'Кол-во скинов: ' + config.skin + '\n' + 'Сумма ставки: ' + config.price_value+ '\n' + '----------------------------------'+ '\n' + coef
else:
text =now.strftime("%d-%m-%Y %H:%M") +'\n'+ '----------------------------------'+ '\n' + 'Игра не началась'+ '\n'+'Кол-во игроков: ' + config.peoples + '\n' + 'Кол-во скинов: ' + config.skin + '\n' + 'Сумма ставки: ' + config.price_value+ '\n' + '----------------------------------'+ '\n' + coef
bot.send_message(id, text)
@bot.message_handler(commands=['coefficient'])
def handle_send_coeff(message):
csfail.prestart()
error_code = 'Невозможно рассчитать коэффициент(ERRORCODE: ' + str(config.status_code) + ')'
if config.status_code != 200:
bot.send_message(message.chat.id, error_code)
else:
csfail.start()
print('Отправитель: ', message.from_user.first_name, message.from_user.last_name, ' [', message.from_user.id, ']', ' Коэффициент: ', str(config.coef))
send_coeff(message.chat.id)
bot.polling()