Skip to content

Commit

Permalink
better exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhky committed Apr 8, 2023
1 parent ecc6afa commit c09aa07
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,26 +456,32 @@ def sending_index_ma(message):


def handle_maplot_callback_query(call):
callbackstr = call.data
if isinstance(call, telebot.types.CallbackQuery):
callbackstr = call.data

if callbackstr == 'button_maplot_sp500':
index = '^GSPC'
plottitle = 'S&P 500 (^GSPC)'
elif callbackstr == 'button_maplot_nasdaq':
index = '^IXIC'
plottitle = 'NASDAQ (^IXIC)'
elif callbackstr == 'button_maplot_dji':
index = '^DJI'
plottitle = 'Dow Jones (^DJI)'
else:
return {}

if callbackstr == 'button_maplot_sp500':
index = '^GSPC'
plottitle = 'S&P 500 (^GSPC)'
elif callbackstr == 'button_maplot_nasdaq':
index = '^IXIC'
plottitle = 'NASDAQ (^IXIC)'
elif callbackstr == 'button_maplot_dji':
index = '^DJI'
plottitle = 'Dow Jones (^DJI)'
plot_info = plotting_index_ma(index, plottitle)
f = urllib.request.urlopen(plot_info['plot']['url'])
bot.send_photo(call.from_user.id, f)
return {
'ploturl': plot_info['plot']['url']
}
elif isinstance(call, telebot.types.Message):
bot.send_message(call.id, 'Internal error. Try again!')
else:
return {}

plot_info = plotting_index_ma(index, plottitle)
f = urllib.request.urlopen(plot_info['plot']['url'])
bot.send_photo(call.from_user.id, f)
return {
'ploturl': plot_info['plot']['url']
}
logging.error('Unknown error!')
print('Unknown error!', file=sys.stderr)


def lambda_handler(event, context):
Expand Down

0 comments on commit c09aa07

Please sign in to comment.