G
G
greeded012021-08-12 17:32:22
Python
greeded01, 2021-08-12 17:32:22

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()


This function should have been a kind of lock and everything in the torii should have worked, but it is when connecting to the function above that problems arise and nothing comes out in the cart
def f1():
    var = cur()
    return var

now = str(f1())


If we replace "var = cur()" with the usual equation, then the cart correctly receives the value "4"
def f1():
    var = (2+2)
    return var

now = str(f1())


Maybe this is due to the very perception of the cart or the need to convert it to text in some way. I would be very happy to help.

Source:
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

1 answer(s)
S
soremix, 2021-08-12
@greeded01

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 question

Ask a Question

731 491 924 answers to any question