Answer the question
In order to leave comments, you need to log in
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.
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
if __name__ == '__main__':
start_process()
try:
bot.polling(none_stop=True)
except:
pass
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) 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 questionAsk a Question
731 491 924 answers to any question