Бот отслеживает курс доллара. При нажатии на Track dollar цикл начинается, а Track off должен остановиться. Пробовал так :
rate = 'True'
@bot.message_handler(content_types = ['text'])
def currency(message):
#parsing goolge
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
#send_message
if message.chat.type == 'private':
if message.text == '❗️ Track off ❗️':
global rate
rate = 'False'
elif message.text == ' Rate dollar ':
bot.send_message(message.chat.id,' Dollar now: ' + str(currency) + ' ₽ ')
#elif message.text == '❗️ Track off ❗️':
#bot.send_message(message.chat.id, 'ok')
if message.text == '❗️ Track off ❗️':
global rate
rate = 'False'
elif message.text == ' Track dollar ':
if rate == 'True':
while True:
price = str(73.4)
differnce = str(0.1)
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
if currency >= price + differnce:
bot.send_message(message.chat.id, ' Course increased: ' + str(currency)+' ')
elif currency <= price - differnce:
bot.send_message(message.chat.id, '〽 Course lowered: ' + str(currency)+' ')
time.sleep(2)
Не получается