Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

currency: Moved to different API, support multiple target currencies, cache rates #1430

Merged
merged 1 commit into from
May 1, 2019

Conversation

Duckle29
Copy link
Contributor

@Duckle29 Duckle29 commented Jan 2, 2019

Hey there. Since I was moving from an old bot to sopel, I wanted to have it mimic what I and others were used to from my old bot. Because of this, I made it support multiple target currencies like:

.cur 100 usd in dkk eur usd aud cad btc

additionally, I moved to https://exchangeratesapi.io/ as the bank of Canada apparently doesn't offer rates for the Danish krona. Exchangeratesapi doesn't have a whole ton of currencies either, but the output is fixer.io compatible, so if it becomes a problem, a simple change would be to add a config section, allowing people to choose between API-key-less, exchangeratesapi.io or getting a free API key from fixer.io

A free API key should be more than enough as well, as the module caches rates for 24h in a global variable, and the free fixer.io plan offers 1000 requests / month

@Duckle29 Duckle29 changed the title Moved to different api, support multiple target currencies, cache rates Currency: Moved to different api, support multiple target currencies, cache rates Jan 2, 2019
@Duckle29
Copy link
Contributor Author

Duckle29 commented Jan 3, 2019

I added the option to configure the module with a fixer.io API key, as fixer.io has 167 currencies while exchangeratesapi.io has 32

additionally, the module can be configured to also respond directly to regex matches.

If no configuration is done, the module defaults to exchangerates.io and no regex.

@dgw dgw added the Feature label Jan 3, 2019
@dgw dgw added this to the 7.0.0 milestone Jan 3, 2019
@dgw dgw changed the title Currency: Moved to different api, support multiple target currencies, cache rates currency: Moved to different api, support multiple target currencies, cache rates Jan 3, 2019
@dgw dgw changed the title currency: Moved to different api, support multiple target currencies, cache rates currency: Moved to different API, support multiple target currencies, cache rates Jan 3, 2019
@dgw
Copy link
Member

dgw commented Jan 3, 2019

Look at that title-edit mess I just made, ugh. 😁

@Duckle29 Are you OK with leaving your master branch untouched for possibly several months? As long as this PR is open, you won't be able to make any other changes on your master without messing up this pull request. It's fine if you are—I don't care what branch name shows up in the merge commit—but it could be inconvenient for you if you forget that master is part of a PR and push something. 😸

@Duckle29
Copy link
Contributor Author

Duckle29 commented Jan 3, 2019

@dgw Yeah that's okay. If I have to work on something in the future I'll make sure to move to a different branch, but for now it works as it should :)

Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preminiary review, with some nitpicks, and some needed changes.

sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @HumorBaby already covered quite a bit before I got to this! I'm mostly pointing out stuff he couldn't know about (because it's only in my head so far).

Besides the line notes left by the two of us, you'll need to rebase this, re-add your new copyright line into the new file header, and sort out the imports: Get them sorted more or less alphabetically and grouped by standard (re and time), third-party (requests), and project (anything under sopel). As explained in one of those comments, we're going to enforce import ordering at some point, so I'm starting to keep an eye out for it already. (And I already fixed a lot of modules' imports in #1402, including this one, so I'm protecting work I already did. 😛)

sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
@dgw dgw removed the Needs Review label Apr 21, 2019
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time I remembered to start a review, instead of spamming a bunch of individual line notes. 🤓

sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary testing with master merged in looks good so far! All previously requested changes have been addressed, and so my final note is: why not throw a test into the example for good measure? 😸

Approving since they are not required 🏅 Bah... accidentally submitted without approving!!! (so approved from my old review)

sopel/modules/currency.py Outdated Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG this is so close! 🚀

sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Outdated Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 🍰

Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this one is pretty important, IMO.

I caught this during testing when I gave an incorrect API key for fixer.io. exchange() has an unhandled error from updated_rates().

To replicate:

  • set fake API key
  • start bot
  • ask for a rate...
  • 💥

sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Show resolved Hide resolved
sopel/modules/currency.py Show resolved Hide resolved
sopel/modules/currency.py Show resolved Hide resolved
@Duckle29
Copy link
Contributor Author

Just a heads up to re-clone my fork if testing it as I squashed a few commits together again.

sopel/modules/currency.py Outdated Show resolved Hide resolved
@dgw dgw requested a review from HumorBaby April 28, 2019 20:14
Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to do this, but I have one small request for this PR 😬 I will admit, however, that it was completely my fault due to a miscommunication in one of my review comments regarding the initialization of the rates_fiat_json dictionary 😭 (see comment). The other is a small style change.

Everything else LGMT 🏅

sopel/modules/currency.py Outdated Show resolved Hide resolved
sopel/modules/currency.py Show resolved Hide resolved
@dgw
Copy link
Member

dgw commented Apr 29, 2019

For the record, I'm perfectly happy to merge this as soon as @HumorBaby's small request is taken care of. We can continue tweaking the actual output format (when to use decimals, how many places, etc.) in a future PR, maybe for Sopel 7.1.

Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving to make it explicit after all the error-handling changes.

Switched to exchangeratesapi.io with fixer.io support
Supports multiple target currencies in one conversion
Can be directly triggered on a regex match if enabled in the config
Removed the separate BTC callable, as the main function handles BTC just fine.
made it caches rates

Co-authored-by: dgw <dgw@technobabbl.es>
Co-authored-by: Humorous Baby <humorbaby@humorbaby.net>
@kwaaak
Copy link
Contributor

kwaaak commented Apr 30, 2019

I've been using it, and it works! 🚀

@dgw dgw merged commit 008a507 into sopel-irc:master May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants