SHARE
TWEET

Untitled

Khalidsm Feb 14th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. from config import token
  3. import telebot
  4. from telebot import types
  5. bot=telebot.TeleBot(token)
  6. contents = requests.get("https://nbu.uz/uz/exchange-rates/json/").json()
  7. print(contents[-1].get("title"))
  8. @bot.message_handler(commands=['dolar'])
  9. def send(message):
  10.     btn=[]
  11.     mk=types.InlineKeyboardMarkup(row_width=3)
  12.     for i in range(len(contents)):
  13.         btn.append(types.InlineKeyboardButton(contents[i].get("title"),callback_data=str(i)))
  14.     mk.add(*btn)
  15.     bot.send_message(message.chat.id,"dollar",reply_markup=mk)
  16. @bot.callback_query_handler(func=lambda call: True)
  17. def callback_inline(call):
  18.     try:
  19.         if call.message:
  20.             for i in range(len(contents)):
  21.                 if call.data ==str(i):
  22.                     bot.send_message(call.message.chat.id,contents[i].get("cb_price"))
  23.                     break
  24.     except Exception as e:
  25.         print(repr(e))
  26. bot.polling()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top