Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions sopel/modules/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ def exchange(bot, match):
bot.reply("Something went wrong while I was getting the exchange rate.")
LOGGER.error("Error in GET request: {}".format(err))
return
except ValueError:
bot.reply("Error: Got malformed data.")
LOGGER.error("Invalid json on update_rates")
except (KeyError, ValueError) as err:
bot.reply("Error: Could not update exchange rates. Try again later.")
LOGGER.error("{} on update_rates".format(
'Invalid JSON' if type(err).__name__ == 'ValueError' else 'Missing JSON value',
))
return
except FixerError as err:
bot.reply('Sorry, something went wrong with Fixer')
Expand Down Expand Up @@ -191,7 +193,6 @@ def update_rates(bot):

response.raise_for_status()
rates_fiat = response.json()
rates_updated = time.time()

rates = rates_fiat['rates']
rates['EUR'] = 1.0 # Put this here to make logic easier
Expand All @@ -202,6 +203,10 @@ def update_rates(bot):
if rate.upper() not in rates:
rates[rate.upper()] = rates_crypto['rates'][rate]['value'] * eur_btc_rate

# if an error aborted the operation prematurely, we want the next call to retry updating rates
# therefore we'll update the stored timestamp at the last possible moment
rates_updated = time.time()


@plugin.command('cur', 'currency', 'exchange')
@plugin.example('.cur 100 usd in btc cad eur',
Expand Down