Пишу бота для отслеживания курса доллара в тг. Есть встроенный keyboard:
При нажатии Track dollar начинается цикл, а при Track off должен остановиться.
код:
пробовал и так:
При нажатии Track dollar начинается цикл, а при Track off должен остановиться.
код:
Python:
@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)
Python:
@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)+' ')