@why2

Python telebot. Пишу бота для отслеживания доллар в тг. Есть встроенный keyboard. Как остановить цикл когда пользователь нажмёт на Track off?

Библиотека telebot. 605a22983930b408807648.pngНе останавливается цикл при нажатии на Track off. Пробовал break не читаться
код:
@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 == ' Rate dollar ':
			
			bot.send_message(message.chat.id,' Dollar now: ' + str(currency) + ' ₽ ')
		
		elif message.text == ' Track dollar ':
			stop = '❗️ Track off ❗️'
			
			while True:	
				if message.text == stop:
					break


				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	
				time.sleep(2)
				
				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)+' ')
  • Вопрос задан
  • 116 просмотров
Пригласить эксперта
Ответы на вопрос 1
@why2 Автор вопроса
Пробовал так:
@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 == ' Rate dollar ':
			
			bot.send_message(message.chat.id,' Dollar now: ' + str(currency) + ' ₽ ')
		while message.text == ' Track dollar ':
			
			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)+' ')
			
			elif message.text == '❗️ Track off ❗️':
				break
			time.sleep(2)

тоже не останавливает
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
18 мая 2024, в 20:58
5000 руб./за проект
18 мая 2024, в 20:53
500 руб./за проект
18 мая 2024, в 20:24
200000 руб./за проект