@why2

Telebot. Как остановить цикл?

Бот отслеживает курс доллара. При нажатии на 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)

Не получается
  • Вопрос задан
  • 390 просмотров
Решения вопроса 1
shabelski89
@shabelski89
engineer
Вот уже кому-то делал бота, парсит разные валюты записывает в БД, чтобы отслеживать динамику.
Будет полезнее код разобрать и переделать, чем по каждому вопросу писать в qna
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы