Answer the question
In order to leave comments, you need to log in
Time.sleep() How to put user value?
Bot in tg. Monitors the dollar exchange rate and sends messages about the dollar (fell, rose). I do not understand how to make the program delay from the user. User input via inline keyboard:
code:
elif message.text == ' Track dollar ':
#keyboard inline
markup = types.InlineKeyboardMarkup(row_width = 2)
kb1 = types.InlineKeyboardButton('10 min', callback_data = '10')
kb2 = types.InlineKeyboardButton('1 horse', callback_data = '1h')
kb3 = types.InlineKeyboardButton('5 horse', callback_data = '10h')
markup.add(kb1, kb2, kb3)
#send message
bot.send_message(message.chat.id, ' Now I am tracking the dollar. ⚡️ \n How long does it take for me to receive notifications❓ \n \n ', reply_markup = markup)
xt()
while True:
if rate == False:
break
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)
inline()
if rate == False:
break
#parsing()
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)
if cur > cur1:
bot.send_message(message.chat.id, ' Course increased: ' + str(cur) + ' ')
elif cur < cur1:
bot.send_message(message.chat.id, ' Course lowered: ' + str(cur) + ' ')
elif cur == cur1:
bot.send_message(message.chat.id, '⚖️ Course has not changed ' + str(cur) + ' 〽️')
@bot.callback_query_handler(func = lambda call: True)
def inline (call):
if call.message:
if call.data == '10':
time.sleep(10)
elif call.data == '1h':
time.sleep(30)
elif call.data == '10h':
time.sleep(60)
Answer the question
In order to leave comments, you need to log in
What does it mean
1 horse
5 horse
kb2 = types.InlineKeyboardButton('1 horse', callback_data = '1h')
kb3 = types.InlineKeyboardButton('5 horse', callback_data = '10h')
def inline (call):
if call.message:
if call.data == '10':
time.sleep(10)
import telebot
import time
import threading
API_TOKEN = '11111111111111111111111111111111'
class my_bot(telebot.TeleBot):
def loop_poop(self):
while True:
print(time.ctime())
time.sleep(1)
def start_action(self):
thread = threading.Thread(target=self.loop_poop)
thread.start()
bot = my_bot(token = API_TOKEN, threaded=False)
@bot.message_handler(commands=['start'])
def wellcome(message):
if message.chat.type == 'private':
bot.send_message(message.chat.id,'Hello')
bot.start_action()
bot.polling()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question