G
G
greeded012021-08-30 21:27:42
Python
greeded01, 2021-08-30 21:27:42

telebot. How to make the page refresh?

The bot at the price of Bitka takes information from the page only once and then simply sends it constantly to the chat.

612d22ed8ca84689772763.png

I tried using return, it did not work, I was glad to help with this

def hhtp_refresh():
    full_page = requests.get(BTCUSDT, headers=headers)
    return full_page


Or make it so that the bot turns on, for example, every 30 seconds, What to do here to do this, I also did not find the answer
if __name__ == '__main__':
    start_process()
    try:
        bot.polling(none_stop=True)
    except:
        pass


Source:
import requests
from bs4 import BeautifulSoup
import telebot
import time
from multiprocessing import *
import schedule
from time import sleep

BTCUSDT = 'https://ru.investing.com/crypto/bitcoin/btc-usd?cid=1035793'
headers = {'User-Agent'}

def hhtp_refresh():
    full_page = requests.get(BTCUSDT, headers=headers)
    return full_page

def get_currency_price():
    soup = BeautifulSoup(hhtp_refresh().content, 'html.parser')
    convert = soup.findAll("span", {"id": "last_last"})
    return (convert[0].text)

def f1():
    var = str(get_currency_price())
    return var

def f2():
    con = float(f1().replace(".", "").replace(",", "."))
    return con

now = ("BTCUSDT= " + str(f2()))

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(5).seconds.do(P_schedule.send_message2)
        schedule.every(2).seconds.do(hhtp_refresh)
        while True:
            schedule.run_pending()
            time.sleep(1)

    def send_message1():
        bot.send_message(ChatID, f'{now}')
    def send_message2():
        bot.send_message(ChatID, 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)
M
mashincode, 2021-08-30
@mashincode

1) Learn to run tasks using Celery
2) Initialize bot and messages and send it, don't include bot.polling method
just
bot = telebot.Telebot(token)
bot.send.....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question