-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
49 lines (41 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
# Copyright (C) 2020 Botir Ziyatov <[email protected]>
# This program is free software: you can redistribute it and/or modify
from telegram import ReplyKeyboardMarkup
from telegram.ext import Updater, CommandHandler, ConversationHandler, MessageHandler, Filters
from covid19 import Covid19
buttons = ReplyKeyboardMarkup([['Statistika'], ['Dunyo']], resize_keyboard=True)
covid = Covid19()
def start(update, context):
update.message.reply_html(
'<b>Assalomu alaykum, {}</b>\n \nMen Koronovirus statistikasi haqida ma`lumot beruvchi botman'.format(update.message.from_user.first_name), reply_markup=buttons)
return 1
def stats(update, context):
data = covid.getByCountryCode('UZ')
update.message.reply_html(
'🇺🇿 <b>O‘zbekistonda</b>\n \n<b>Yuqtirganlar:</b> {}\n<b>Sog‘ayganlar:</b> {}\n<b>Vafot etganlar:</b> {}'.
format(
data['confirmed'],
data['recovered'],
data['deaths']), reply_markup=buttons)
def world(update, context):
data = covid.getLatest()
update.message.reply_html(
'🌎 <b>Dunyoda</b>\n \n<b>Yuqtirganlar:</b> {}\n<b>Sog‘ayganlar:</b> {}\n<b>Vafot etganlar:</b> {}'.format(
"{:,}".format(data['confirmed']),
"{:,}".format(data['recovered']),
"{:,}".format(data['deaths'])
), reply_markup=buttons)
updater = Updater('TOKEN', use_context=True)
conv_handler = ConversationHandler(
entry_points = [CommandHandler('start', start)],
states={
1: [MessageHandler(Filters.regex('^(Statistika)$'), stats),
MessageHandler(Filters.regex('^(Dunyo)$'), world),
]
},
fallbacks=[MessageHandler(Filters.text, start)]
)
updater.dispatcher.add_handler(conv_handler)
updater.start_polling()
updater.idle()