Answer the question
In order to leave comments, you need to log in
TELEBOT Why doesn't the bot only work on 2 devices?
I wrote a bot in tenge, it monitors the exchange rate of the dollar, bitcoin, etc. I started testing, asked my friends to test too, after 3 minutes the bot stopped responding? What can be done?
if message.chat.type == 'private':
if message.text == ' Rate dollar ':
bot.send_sticker(message.chat.id, open('sticker/dollar.webp', 'rb'))
bot.send_message(message.chat.id,' Dollar now: ' + str(cur) + ' ₽ ')
elif message.text == '₿ Rate Bitcoin ₿':
bot.send_sticker(message.chat.id, open('sticker/bitcoin.webp', 'rb'))
bot.send_message(message.chat.id, 'Bitcoin now: ' + str(bit1))
elif message.text == 'Track Bitcoin₿ and Dollar$':
markupda = types.InlineKeyboardMarkup(row_width=True)
kn = types.InlineKeyboardButton('❗️ Track off ❗️', callback_data = 'off')
markupda.add(kn)
bot.send_sticker(message.chat.id, open('sticker/sticker1.webp', 'rb'))
bot.send_message(message.chat.id, 'I started following course $ and ₿.\n You will receive messages every hour \n Dollar now: ' + str(cur) + ' ₽ \n Bitcoin now: ' + str(bit1) + ' ₽ ', reply_markup=markupda )
xt()
while True:
if rate == False:
break
#parsing old
#dollar
full_page1 = requests.get(url, headers = headers)
soup1 = BeautifulSoup(full_page1.content, 'html.parser')
convert1 = soup1.findAll('span', {'class': 'DFlfde', 'class': 'SwHCTb', 'data-precision': 2})
currency1 = convert1[0].text.replace(',','.')
cur1 = float(currency1)
#old bit
page_f = requests.get(url2, headers = headers)
pars = BeautifulSoup(page_f.content, 'html.parser')
parsingbit = pars.findAll('span', {'class': 'DFlfde', 'class': 'SwHCTb', 'data-precision': 2})
bitcoin = parsingbit[0].text.replace(',','.')
bit = bitcoin
bitd = ''.join(bit.split())
time.sleep(120)
if rate == False:
break
#parsing new
#dollar
full_page = requests.get(url, headers = headers)
soup = BeautifulSoup(full_page.content, 'html.parser')
convert = soup.findAll('span', {'class': 'DFlfde', 'class': 'SwHCTb', 'data-precision': 2})
currency = convert[0].text.replace(',','.')
cur = float(currency)
# difference
dif1 = (cur - cur1)
dif2 = (cur1 - cur)
#send message
#dollar
if cur > cur1:
bot.send_sticker(message.chat.id, open('sticker/idollar.webp', 'rb'))
bot.send_message(message.chat.id, ' Course $ increased: ' + str(cur)+ ' ₽\n' + 'Difference: ' + '+' + str(round(dif1, 3)) + ' ₽', reply_markup = markupda)
elif cur < cur1:
bot.send_sticker(message.chat.id, open('sticker/ldollar.webp', 'rb'))
bot.send_message(message.chat.id, ' Course $ lowered: ' + str(cur)+ ' ₽\n' + 'Difference: ' + '-' + str(round(dif2, 3)) + ' ₽')
elif cur == cur1:
bot.send_sticker(message.chat.id, open('sticker/hasdollar.webp', 'rb'))
bot.send_message(message.chat.id, '⚖️ Course $ has not changed: ' + str(cur) + ' ₽')
else:
bot.send_message(message.chat.id, '⭕️ Error ⭕️. Do you want to help me? Write /help_me')
#new bit
page_f1 = requests.get(url2, headers = headers)
pars1 = BeautifulSoup(page_f1.content, 'html.parser')
parsingbit1 = pars1.findAll('span', {'class': 'DFlfde', 'class': 'SwHCTb', 'data-precision': 2})
bitcoin1 = parsingbit1[0].text.replace(',','.')
bit1 = bitcoin1
bit1d = ''.join(bit1.split())
#difference
difference = (float(bitd) - float(bit1d))
difference1 = (float(bit1d) - float(bitd))
if bit > bit1:
bot.send_sticker(message.chat.id, open('sticker/bottom.webp', 'rb'))
bot.send_message(message.chat.id, ' Course ₿ lowered: ' + str(bit1) + ' ₽\n' + 'Difference: ' + '-' + str(round(difference, 3)) + ' ')
elif bit < bit1:
bot.send_sticker(message.chat.id, open('sticker/i.webp', 'rb'))
bot.send_message(message.chat.id, ' Course ₿ increased: ' + str(bit1) + ' ₽\n' + 'Difference: ' + '+' + str(round(difference1, 3)) + ' ')
elif bit == bit1:
bot.send_sticker(message.chat.id, open('sticker/hasdollar.webp', 'rb'))
bot.send_message(message.chat.id, '⚠️ Course ₿ has not changed: ' + str(bit1) + ' ₽')
else:
bot.send_message(message.chat.id, '⭕️ Error ⭕️. Do you want to help me? Write /help_me')
Answer the question
In order to leave comments, you need to log in
Look... in short:
you are not writing a bot, not a dollar parser... You are writing a program first of all! And the time.sleep(120) command stops the ALL program for 120 seconds
. And the while True command: Loops the ALL program in one place and whoever clicked it first muted it, but the program will not crash and will not give an error because it works! just not right. These two lines must be removed completely, and with this, the entire logic of the program must be rewritten ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question