1. Bu qanday bot bo'ladi?



Download 336,31 Kb.
Pdf ko'rish
bet10/11
Sana30.08.2021
Hajmi336,31 Kb.
#159541
1   2   3   4   5   6   7   8   9   10   11
Bog'liq
Pythonda telegram bot yaratish

non_stop=Trueto'xtovsiz ishlashini ta'minlaydi. 

Vanihoyat, dasturning barcha bo'laklarni bitta joyga yig'amiz: 

import telebot 

 # connect all modules 

from telebot import types 

import config 

import covid19cases as covid 

 

# connect bot to code 



bot = telebot.TeleBot('token') 


 

 

# check command start 



@bot.message_handler(commands=['start']) 

def send_welcome(message): 

# send sticker 

    sticker = open('sticker_three.webp', 'rb') 

    bot.send_sticker(message.chat.id, sticker) 

    hello_text = "Salom, {0}!\n{1} botiga xush kelibsiz!\nSo'ngi 

ma'lumotlarni olish uchun davlatni 

tanlang".format(message.from_user.first_name, bot.get_me().first_name) 

 

# make keyboard 



    markup = types.ReplyKeyboardMarkup() 

    itembtna = types.KeyboardButton('Aqsh') 

    itembtnr = types.KeyboardButton('Rossiya') 

    itembtnx = types.KeyboardButton('Xitoy') 

    itembtni = types.KeyboardButton('Ispaniya') 

    itembtnit = types.KeyboardButton('Italiya') 

    itembtnu = types.KeyboardButton('O\'zbekiston') 

    markup.row(itembtna, itembtnx, itembtnr) 

    markup.row(itembtni, itembtnit, itembtnu) 

    bot.send_message(message.chat.id, hello_text, reply_markup=markup) 

 

# check contetn 



@bot.message_handler(content_types=["text"]) 

def get_information(message): 

    if message.chat.type == 'private': 

     


# check which button selected user 

        if message.text == 'Aqsh': 

            res = covid.get_country_cases("USA") 

        elif message.text == 'Ispaniya': 

            res = covid.get_country_cases("Spain") 

        elif message.text == 'Rossiya': 

            res = covid.get_country_cases("Russia") 

        elif message.text == 'O\'zbekiston': 

            res = covid.get_country_cases("Uzbekistan") 

        elif message.text == 'Buyuk Britaniya': 

            res = covid.get_country_cases("UK") 

        elif message.text == 'Italiya': 

            res = covid.get_country_cases("Italy") 

        elif message.text == 'Fransiya': 

            res = covid.get_country_cases("France") 

        elif message.text == 'Germaniya': 

            res = covid.get_country_cases("Germany") 

        elif message.text == 'Turkiya': 

            res = covid.get_country_cases("Turkey") 

        elif message.text == 'Xitoy': 

            res = covid.get_country_cases("China") 

        else: 

            res = covid.get_global_cases() 

 

 



 

 

#send user all text with information 



        lat = res['TotalCases'] 

        new = res['NewCases'] 

        deth = res['TotalDeaths'] 

        rec = res['TotalRecovered'] 

        text = "Jami kasallanganlar soni: {0}\nBugun aniqlangan bemorlar 

soni: {1}\nJami o'limlar soni: {2}\nJami tuzalganlar soni: {3}\nAgarda bu 




sonlar ortishini istamasangiz Uyda qoling".format(lat, 

new.replace("+", ""), deth, rec) 

        bot.send_message(message.chat.id, text, parse_mode='html') 

 

 



# run programm non-stop 

bot.polling(none_stop=True) 

# Ans it's end 


Download 336,31 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   11




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish