Answer the question
In order to leave comments, you need to log in
Telebot, nothing comes out in the telegram, although it displays a value in the console, how to fix it?
I want to make a small bot with alerts. It consists of two parts, the first one that looks at the price and regularly enters it into the console, the second part is responsible for the cart and the message cycle, it also works properly. But during the final symbiosis, there are no inscriptions, except for the price in the console, nothing comes out in the cart, there are no errors or the inscription "None" in the cart either.
This function is my key to enable the first part
def cur():
currency = Currency()
currency.check_currency()
def f1():
var = cur()
return var
now = str(f1())
def f1():
var = (2+2)
return var
now = str(f1())
import requests
from bs4 import BeautifulSoup
import telebot
import time
from multiprocessing import *
import schedule
class Currency:
BTCUSDT = 'https://ru.investing.com/crypto/bitcoin/btc-usd?cid=1035793'
headers = {"Юзер агент"}
current_converted_price = 0
def __init__(self):
self.current_converted_price = float(self.get_currency_price().replace(".", "").replace(",", "."))
def get_currency_price(self):
full_page = requests.get(self.BTCUSDT, headers=self.headers)
soup = BeautifulSoup(full_page.content, 'html.parser')
convert = soup.findAll("span", {"id": "last_last"})
return convert[0].text
def check_currency(self):
currency = float(self.get_currency_price().replace(".", "").replace(",", "."))
print("BTCUSDT=" + str(currency))
self.check_currency()
def cur():
currency = Currency()
currency.check_currency()
def f1():
var = cur()
return var
now = str(f1())
API_TOKEN = 'API'
bot = telebot.TeleBot(API_TOKEN)
def start_process(): p1 = Process(target=P_schedule.start_schedule, args=()).start()
class P_schedule():
def start_schedule():
schedule.every().day.at("03:00").do(P_schedule.send_message1)
schedule.every(3).seconds.do(P_schedule.send_message2)
while True:
schedule.run_pending()
time.sleep(1)
def send_message1():
bot.send_message(Chat_ID, f'{now}')
def send_message2():
bot.send_message(Chat_ID, f'{now}')
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Нажали start')
if __name__ == '__main__':
start_process()
try:
bot.polling(none_stop=True)
except:
pass
Answer the question
In order to leave comments, you need to log in
The code doesn't even get to the start of the bot, it doesn't go beyond the call check_currency
, because the function is in an infinite loop
def check_currency(self):
currency = float(self.get_currency_price().replace(".", "").replace(",", "."))
print("BTCUSDT=" + str(currency))
self.check_currency()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question