From fe4ffba0316552387cb0f748c3b3c405b87ac96f Mon Sep 17 00:00:00 2001 From: Anson Date: Thu, 11 Jul 2019 21:54:43 -0700 Subject: [PATCH] operational version of telegram bot --- functions.py | 4 ++-- telegramBot.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/functions.py b/functions.py index 40dcca1..8ee4d98 100644 --- a/functions.py +++ b/functions.py @@ -11,7 +11,7 @@ def nextLaunch(): "rocket": "Proton-M/Blok DM-03 ", "mission": " Spektr-RG", "date": "July 12, 2019 12:31:00 UTC", - "countdown": "The launch is in 14 hours and 48 minutes.", + "countdown": "14 hours and 48 minutes.", "video": "https://www.youtube.com/watch?v=Dy1nkGghEVk", } """ @@ -29,7 +29,7 @@ def nextLaunch(): countdown = str( datetime.strptime(date, "%B %d, %Y %H:%M:%S %Z") - datetime.today() ).split(":") - countdown = f"The launch is in {countdown[0]} hours and {countdown[1]} minutes." + countdown = f"{countdown[0]} hours and {countdown[1]} minutes." else: print("error") diff --git a/telegramBot.py b/telegramBot.py index 404fc6a..f58f0b0 100644 --- a/telegramBot.py +++ b/telegramBot.py @@ -24,11 +24,13 @@ def start(bot, update): update.message.reply_text("I am started and ready to go!") -def nextRocketLaunch(): - nextLaunch() - +def nextRocketLaunch(bot, update): + launch = nextLaunch() + message = f"The **{launch['mission']}** is in {launch['countdown']}\n\n" + message += f"The Mission is using the {launch['rocket']} and you can watch the mission live [here]({launch['video']})" + update.message.reply_text(text=message, parse_mode=telegram.ParseMode.MARKDOWN) def error(bot, update, error): @@ -46,7 +48,7 @@ def main(): # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) - dp.add_handler(CommandHandler("Launch", nextRocketLaunch)) + dp.add_handler(CommandHandler("launch", nextRocketLaunch)) # log all errors dp.add_error_handler(error)