~josealberto4444/apodnasabot

bb84e60c2af7ff8621e49da8d4add6454889f647 — José Alberto Orejuela García 4 years ago 812c83a
Handle dates out of range
1 files changed, 11 insertions(+), 8 deletions(-)

M telegram_bot.py
M telegram_bot.py => telegram_bot.py +11 -8
@@ 33,14 33,18 @@ def send_apod(update: telegram.Update, context: telegram.ext.CallbackContext):
            apod = api.Apod(date)
    else:
        apod = api.Apod()
    if apod.media_type == 'image':
        update.message.reply_photo(photo=apod.link, caption=apod.title)
    elif apod.media_type == 'video':
        update.message.reply_text(apod.link)
    if apod.html:
        context.bot.send_message(chat_id=update.message.chat_id, text=apod.explanation, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True)
    if apod.error:
        context.bot.send_message(chat_id=update.message.chat_id, text=apod.error)
    else:
        context.bot.send_message(chat_id=update.message.chat_id, text=apod.explanation)
        if apod.media_type == 'image':
            update.message.reply_photo(photo=apod.link, caption=apod.title)
        elif apod.media_type == 'video':
            text = apod.title + '\n' + apod.link
            update.message.reply_text(text)
        if apod.html:
            context.bot.send_message(chat_id=update.message.chat_id, text=apod.explanation, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True)
        else:
            context.bot.send_message(chat_id=update.message.chat_id, text=apod.explanation)

send_apod_handler = telegram.ext.CommandHandler('apod', send_apod)
dispatcher.add_handler(send_apod_handler)


@@ 77,7 81,6 @@ dispatcher.add_handler(start_handler)
#dispatcher.add_handler(echo_handler)
#
#def caps(update, context):
#    print(context.args)
#    text_caps = ' '.join(context.args).upper()
#    context.bot.send_message(chat_id=update.message.chat_id, text=text_caps)
#