import requests
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
BOT_TOKEN = "7997907072:AAEcUopih7hkMY5iHb29DIkDKjMNFOLtE1g"
async def get_covid_stats(country: str) -> str:
try:
url = f"https://disease.sh/v3/covid-19/countries/{country}"
response = requests.get(url, timeout=5)
response.raise_for_status()
data = response.json()
return (
f"🦠 **COVID-19 Stats for {data['country']}**👇🏻\n\n"
f"📊 **Total Cases**: {data['cases']:,}\n"
f"🔥 **Active Cases**: {data['active']:,}\n"
f"💀 **Deaths**: {data['deaths']:,}\n"
f"✅ **Recovered**: {data['recovered']:,}\n"
f"🕒 **Last Updated**: {data['updated'] // 1000}"
)
except requests.exceptions.RequestException:
return "⚠️ Invalid country name.\n Example: `/covid India`"
except KeyError:
return "❌ Error in fetching data.\n Please try again later."
async def covid_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
if not context.args:
await update.message.reply_text("❗ Please specify a country.\n Example: `/covid india`", parse_mode="Markdown")
return
country = " ".join(context.args).strip().lower()
covid_info = await get_covid_stats(country)
await update.message.reply_text(covid_info, parse_mode="Markdown")
def main():
application = Application.builder().token(BOT_TOKEN).build()
application.add_handler(CommandHandler("covid", covid_command))
print("🤖 Bot is running...")
application.run_polling()
if __name__ == "__main__":
main()
𝑪𝑹𝑬𝑫𝑰𝑻- @daddy_chips
🎉4👎2
