Closed KolbyML closed 5 years ago
Hello, As you can probably guess from the commits, I add the new rates in the sources about twice a week, so people cloning from GitHub have fresh rates. PyPI is updated much less often.
Nevertheless, you can get the latest rates by changing the CurrencyConverter
initialization (also works with a local file):
>>> from currency_converter import CurrencyConverter
>>> c = CurrencyConverter('http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip')
Oh that's unfortunate.
Do you think you could add a function to check for the latest rates?
I am not sure I understand.
Basically by using the piece of code above, you ensure that you are using the latest available rates. Adding a function to check for rates would just download the data again, so using this way of creating the CurrencyConverter
is what you need, I think.
I just feel like it should be built into the library instead of updating the GitHub repo every time
But you don't need to update the GitHub repo, as I explained in my previous comment.
What you need to do is to create the CurrencyConverter
object this way:
from currency_converter import CurrencyConverter
c = CurrencyConverter('http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip')
Then it will download the latest available rates from the url. Adding some sort of method like c.update_rates()
would just be implemented by re-doing the __init__
with a different argument:
c = CurrencyConverter() # created with the embedded data from the repo
c.__init__('http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip')
# rates have been updated
If you find this ugly, you can add your own method either by subclassing or just:
URL = 'http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip'
CurrencyConverter.update_rates = lambda self: self.__init__(URL)
c = CurrencyConverter()
c.update_rates() # rates have been updated
Sorry to yet again awaken an old thread. But if I do c = CurrencyConverter('...')
, can I later do c.__init__('...')
to update, or will it keep using the one it downloaded on creation of the object?
It will download it again.
Doe the rates auto update?