From 94e23379600221e64866dc2ba60a54d1f65da6be Mon Sep 17 00:00:00 2001 From: ravigadila Date: Wed, 27 Mar 2019 14:30:58 +0530 Subject: [PATCH 01/31] add forex-python parameter to ratesapi.io --- README.rst | 5 ++++- docs/source/conf.py | 6 +++--- docs/source/index.rst | 2 +- forex_python/converter.py | 6 +++--- setup.py | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 16bf64b..bfc91dd 100644 --- a/README.rst +++ b/README.rst @@ -3,16 +3,19 @@ forex-python .. image:: https://travis-ci.org/MicroPyramid/forex-python.svg?branch=master :target: https://travis-ci.org/MicroPyramid/forex-python + :alt: travis-ci .. image:: https://coveralls.io/repos/github/MicroPyramid/forex-python/badge.svg?branch=master :target: https://coveralls.io/github/MicroPyramid/forex-python?branch=master + :alt: coveralls -.. image:: https://landscape.io/github/MicroPyramid/forex-python/master/landscape.svg?style=plastic +.. image:: https://landscape.io/github/MicroPyramid/forex-python/master/landscape.svg?style=flat :target: https://landscape.io/github/MicroPyramid/forex-python/master :alt: Code Health .. image:: https://img.shields.io/badge/python-2.7%2C%203.3%2C%203.4%2C%203.5-blue.svg :target: https://pypi.python.org/pypi/forex-python + :alt: pypi Forex Python is a Free Foreign exchange rates and currency conversion. diff --git a/docs/source/conf.py b/docs/source/conf.py index 7f093c9..5947aa1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -51,7 +51,7 @@ # General information about the project. project = u'forex-python' -copyright = u'2016, MicroPyramid Informatics Pvt. Ltd.' +copyright = u'2019, MicroPyramid Informatics Pvt. Ltd.' author = u'MicroPyramid Informatics Pvt. Ltd.' # The version info for the project you're documenting, acts as replacement for @@ -59,9 +59,9 @@ # built documents. # # The short X.Y version. -version = u'0.3.0' +version = u'1.2' # The full version, including alpha/beta/rc tags. -release = u'0.3.0' +release = u'1.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/index.rst b/docs/source/index.rst index 2b1ed73..c009d5f 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -6,7 +6,7 @@ Free Foreign exchange rates, bitcoin prices and currency conversion. Features: --------- - List all currency rates. -- BitCoin price for all curuncies. +- BitCoin price for all currencies. - Converting amount to BitCoins. - Get historical rates for any day since 1999. - Conversion rate for one currency(ex; USD to INR). diff --git a/forex_python/converter.py b/forex_python/converter.py index 6717d6d..dfcbcd7 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -47,7 +47,7 @@ class CurrencyRates(Common): def get_rates(self, base_cur, date_obj=None): date_str = self._get_date_string(date_obj) - payload = {'base': base_cur} + payload = {'base': base_cur, 'rtype': 'fpy'} source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: @@ -61,7 +61,7 @@ def get_rate(self, base_cur, dest_cur, date_obj=None): return Decimal(1) return 1. date_str = self._get_date_string(date_obj) - payload = {'base': base_cur, 'symbols': dest_cur} + payload = {'base': base_cur, 'symbols': dest_cur, 'rtype': 'fpy'} source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: @@ -84,7 +84,7 @@ def convert(self, base_cur, dest_cur, amount, date_obj=None): return float(amount) date_str = self._get_date_string(date_obj) - payload = {'base': base_cur, 'symbols': dest_cur} + payload = {'base': base_cur, 'symbols': dest_cur, 'rtype': 'fpy'} source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: diff --git a/setup.py b/setup.py index d71ffd9..2db1149 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os from setuptools import setup, find_packages -VERSION = '1.1' +VERSION = '1.2' long_description_text = """Forex Python is a Free Foreign exchange rates and currency conversion. Features: List all currency rates. From 5c9a72758f4ddb5ff8742eb5759b5cfa53c8167d Mon Sep 17 00:00:00 2001 From: ravigadila Date: Wed, 27 Mar 2019 14:50:03 +0530 Subject: [PATCH 02/31] fixed verson number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2db1149..ef2357e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os from setuptools import setup, find_packages -VERSION = '1.2' +VERSION = '1.4' long_description_text = """Forex Python is a Free Foreign exchange rates and currency conversion. Features: List all currency rates. From a259839bd84116ea5a145cec1f20ab95ac069b90 Mon Sep 17 00:00:00 2001 From: ravigadila Date: Fri, 5 Apr 2019 21:13:36 +0530 Subject: [PATCH 03/31] change source url --- forex_python/converter.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index dfcbcd7..d2b1a78 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -24,7 +24,7 @@ def __init__(self, force_decimal=False): self._force_decimal = force_decimal def _source_url(self): - return "https://ratesapi.io/api/" + return "https://api.ratesapi.io/api/" def _get_date_string(self, date_obj): if date_obj is None: diff --git a/setup.py b/setup.py index ef2357e..abe5da6 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os from setuptools import setup, find_packages -VERSION = '1.4' +VERSION = '1.5' long_description_text = """Forex Python is a Free Foreign exchange rates and currency conversion. Features: List all currency rates. From 1aeb8323829ff965aa74a7fbfb931269dd52657c Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 6 Jul 2019 15:33:39 -0500 Subject: [PATCH 04/31] Add Bitcoin symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bitcoin Unicode symbol ₿ released with version 10.0 --- forex_python/raw_data/currencies.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/forex_python/raw_data/currencies.json b/forex_python/raw_data/currencies.json index aee370b..ab395cf 100644 --- a/forex_python/raw_data/currencies.json +++ b/forex_python/raw_data/currencies.json @@ -20,6 +20,7 @@ {"cc":"BOB","symbol":"Bs.","name":"Bolivian boliviano"}, {"cc":"BRL","symbol":"R$","name":"Brazilian real"}, {"cc":"BSD","symbol":"B$","name":"Bahamian dollar"}, + {"cc":"BTC","symbol":"₿","name":"Bitcoin"}, {"cc":"BTN","symbol":"Nu.","name":"Bhutanese ngultrum"}, {"cc":"BWP","symbol":"P","name":"Botswana pula"}, {"cc":"BYR","symbol":"Br","name":"Belarusian ruble"}, @@ -155,4 +156,4 @@ {"cc":"ZAR","symbol":"R","name":"South African rand"}, {"cc":"ZMK","symbol":"ZK","name":"Zambian kwacha"}, {"cc":"ZWR","symbol":"Z$","name":"Zimbabwean dollar"} -] \ No newline at end of file +] From 84ece2cc6d207391fbbee4863e630f3a62df54c9 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Tue, 17 Dec 2019 07:32:18 +1100 Subject: [PATCH 05/31] Fix simple typo: prevois -> previous Closes #74 --- docs/source/usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 76c6f4d..779e478 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -60,7 +60,7 @@ Bitcoin Prices: >>> b.get_latest_price('EUR') # you can directly call get_latest_price('EUR') 476.5225 # return type float -2. Get price of Bitcoin based on prevois date:: +2. Get price of Bitcoin based on previous date:: >>> date_obj datetime.datetime(2016, 5, 18, 19, 39, 36, 815417) >>> b.get_previous_price('USD', date_obj) # get_previous_price('USD', date_obj) From 97c50601308d94b84b6a9ae77f6ca671a263e5b4 Mon Sep 17 00:00:00 2001 From: sergey-scat <31442538+sergey-scat@users.noreply.github.com> Date: Thu, 4 Jun 2020 10:47:40 +0300 Subject: [PATCH 06/31] Update Russian ruble symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currency symbol of The Russian ruble is ₽ (the encoding U+20BD): https://en.wikipedia.org/wiki/Russian_ruble https://unicode-table.com/en/20BD/ --- forex_python/raw_data/currencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/raw_data/currencies.json b/forex_python/raw_data/currencies.json index ab395cf..ed57ae3 100644 --- a/forex_python/raw_data/currencies.json +++ b/forex_python/raw_data/currencies.json @@ -117,7 +117,7 @@ {"cc":"QAR","symbol":"QR","name":"Qatari riyal"}, {"cc":"RON","symbol":"L","name":"Romanian leu"}, {"cc":"RSD","symbol":"din.","name":"Serbian dinar"}, - {"cc":"RUB","symbol":"R","name":"Russian ruble"}, + {"cc":"RUB","symbol":"\u20bd","name":"Russian ruble"}, {"cc":"SAR","symbol":"SR","name":"Saudi riyal"}, {"cc":"SBD","symbol":"SI$","name":"Solomon Islands dollar"}, {"cc":"SCR","symbol":"SR","name":"Seychellois rupee"}, From 2c219150a3fbbc5516cd87cd2e94bc5b98427ce0 Mon Sep 17 00:00:00 2001 From: iRajMishra <72180377+iRajMishra@users.noreply.github.com> Date: Thu, 1 Oct 2020 09:55:00 +0530 Subject: [PATCH 07/31] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index bfc91dd..7f7f019 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ Forex Python is a Free Foreign exchange rates and currency conversion. **Note: Install latest forex-python==1.1 to avoid RatesNotAvailableError** -Features: +Features of Forex Python: --------- - List all currency rates. - BitCoin price for all currencies. From 6162b5b831ea117b6e3921d72d3b16739267ba1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=81ajszczak?= Date: Sun, 25 Oct 2020 09:41:22 +0000 Subject: [PATCH 08/31] instructs to use latest 1.5 to avoid error --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index bfc91dd..24853b5 100644 --- a/README.rst +++ b/README.rst @@ -19,7 +19,7 @@ forex-python Forex Python is a Free Foreign exchange rates and currency conversion. -**Note: Install latest forex-python==1.1 to avoid RatesNotAvailableError** +**Note: Install latest forex-python==1.5 to avoid RatesNotAvailableError** Features: --------- From d6f62a23c82b2f5c3cdb06208ee2e72aa86b5ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 29 Dec 2020 23:55:05 +0100 Subject: [PATCH 09/31] Raise exception when rate date is not the requested The API return the latest rate when requesting a rate for a date for which it is not yet available like in the future. --- forex_python/converter.py | 25 ++++++++++++++++--------- tests/test.py | 9 +++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index d2b1a78..bc0a7ce 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -32,15 +32,21 @@ def _get_date_string(self, date_obj): date_str = date_obj.strftime('%Y-%m-%d') return date_str - def _decode_rates(self, response, use_decimal=False): + def _decode_rates(self, response, use_decimal=False, date_str=None): if self._force_decimal or use_decimal: - decoded_data = json.loads(response.text, use_decimal=True).get('rates', {}) + decoded_data = json.loads(response.text, use_decimal=True) else: - decoded_data = response.json().get('rates', {}) - return decoded_data + decoded_data = response.json() + if (date_str and date_str != 'latest' + and date_str != decoded_data.get('date')): + raise RatesNotAvailableError("Currency Rates Source Not Ready") + return decoded_data.get('rates', {}) - def _get_decoded_rate(self, response, dest_cur, use_decimal=False): - return self._decode_rates(response, use_decimal=use_decimal).get(dest_cur, None) + def _get_decoded_rate( + self, response, dest_cur, use_decimal=False, date_str=None): + return self._decode_rates( + response, use_decimal=use_decimal, date_str=date_str).get( + dest_cur, None) class CurrencyRates(Common): @@ -51,7 +57,7 @@ def get_rates(self, base_cur, date_obj=None): source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: - rates = self._decode_rates(response) + rates = self._decode_rates(response, date_str=date_str) return rates raise RatesNotAvailableError("Currency Rates Source Not Ready") @@ -65,7 +71,7 @@ def get_rate(self, base_cur, dest_cur, date_obj=None): source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: - rate = self._get_decoded_rate(response, dest_cur) + rate = self._get_decoded_rate(response, dest_cur, date_str=date_str) if not rate: raise RatesNotAvailableError("Currency Rate {0} => {1} not available for Date {2}".format( base_cur, dest_cur, date_str)) @@ -88,7 +94,8 @@ def convert(self, base_cur, dest_cur, amount, date_obj=None): source_url = self._source_url() + date_str response = requests.get(source_url, params=payload) if response.status_code == 200: - rate = self._get_decoded_rate(response, dest_cur, use_decimal=use_decimal) + rate = self._get_decoded_rate( + response, dest_cur, use_decimal=use_decimal, date_str=date_str) if not rate: raise RatesNotAvailableError("Currency {0} => {1} rate not available for Date {2}.".format( source_url, dest_cur, date_str)) diff --git a/tests/test.py b/tests/test.py index 610657a..4add1db 100644 --- a/tests/test.py +++ b/tests/test.py @@ -39,6 +39,10 @@ def test_get_rates_with_date(self): def test_get_rates_invalid_code(self): self.assertRaises(RatesNotAvailableError, get_rates, 'XYZ') + def test_get_rates_in_future(self): + future = datetime.date.today() + datetime.timedelta(days=1) + self.assertRaises(RatesNotAvailableError, get_rates, 'USD', future) + class TestGetRate(TestCase): """ @@ -67,6 +71,11 @@ def test_get_rate_with_invalid_codes(self): # raise exception for invalid currency codes self.assertRaises(RatesNotAvailableError, get_rate, 'ABCD', 'XYZ') + def test_get_rates_in_future(self): + future = datetime.date.today() + datetime.timedelta(days=1) + self.assertRaises( + RatesNotAvailableError, get_rate, 'EUR', 'USD', future) + class TestAmountConvert(TestCase): """ From bf9888b5523c7114b37a5d9a4d78e660ffe0efc7 Mon Sep 17 00:00:00 2001 From: ravi Date: Sun, 6 Jun 2021 18:12:23 +0530 Subject: [PATCH 10/31] change api --- forex_python/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index bc0a7ce..d1192b7 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -24,7 +24,7 @@ def __init__(self, force_decimal=False): self._force_decimal = force_decimal def _source_url(self): - return "https://api.ratesapi.io/api/" + return "https://theforexapi.com/api/" def _get_date_string(self, date_obj): if date_obj is None: From 92cf7a80377b13091707c7d45fce4280bd5b5fc6 Mon Sep 17 00:00:00 2001 From: ravi Date: Sun, 6 Jun 2021 18:15:24 +0530 Subject: [PATCH 11/31] change in docs --- README.rst | 2 +- docs/source/currencysource.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 4db9f93..868cd67 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,7 @@ Features of Forex Python: Currency Source: ----------------- -https://ratesapi.io is a free API for current and historical foreign exchange rates published by European Central Bank. +https://theforexapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. The rates are updated daily 3PM CET. BitCoin Price Source: diff --git a/docs/source/currencysource.rst b/docs/source/currencysource.rst index 07b06b9..170281a 100644 --- a/docs/source/currencysource.rst +++ b/docs/source/currencysource.rst @@ -1,9 +1,9 @@ currency source =============== -https://ratesapi.io +https://theforexapi.com -------- -https://ratesapi.io is a free API for current and historical foreign exchange rates published by European Central Bank. The rates are updated daily 3PM CET. +https://theforexapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. The rates are updated daily 3PM CET. List of Supported Currency codes. --------------------------------- From 59455fdd71d6cb423754d414e3c3c42f74c54142 Mon Sep 17 00:00:00 2001 From: chaitanya Date: Tue, 8 Jun 2021 16:35:46 +0530 Subject: [PATCH 12/31] 1.6 version release --- README.rst | 2 +- docs/source/conf.py | 6 +++--- setup.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 868cd67..6bc71d2 100644 --- a/README.rst +++ b/README.rst @@ -19,7 +19,7 @@ forex-python Forex Python is a Free Foreign exchange rates and currency conversion. -**Note: Install latest forex-python==1.5 to avoid RatesNotAvailableError** +**Note: Install latest forex-python==1.6 to avoid RatesNotAvailableError** Features of Forex Python: --------- diff --git a/docs/source/conf.py b/docs/source/conf.py index 5947aa1..4e7c981 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -51,7 +51,7 @@ # General information about the project. project = u'forex-python' -copyright = u'2019, MicroPyramid Informatics Pvt. Ltd.' +copyright = u'2021, MicroPyramid Informatics Pvt. Ltd.' author = u'MicroPyramid Informatics Pvt. Ltd.' # The version info for the project you're documenting, acts as replacement for @@ -59,9 +59,9 @@ # built documents. # # The short X.Y version. -version = u'1.2' +version = u'1.6' # The full version, including alpha/beta/rc tags. -release = u'1.2' +release = u'1.6' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index abe5da6..de66932 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os from setuptools import setup, find_packages -VERSION = '1.5' +VERSION = '1.6' long_description_text = """Forex Python is a Free Foreign exchange rates and currency conversion. Features: List all currency rates. From ffcf2c8fbc82747a8bb0b0372afa13ff902c00f1 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Tue, 8 Jun 2021 23:12:55 +0530 Subject: [PATCH 13/31] Update converter.py --- forex_python/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index d1192b7..567e9f8 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -6,7 +6,7 @@ class RatesNotAvailableError(Exception): """ - Custome Exception when https://ratesapi.io is Down and not available for currency rates + Custome Exception when https://theforexapi.com is Down and not available for currency rates """ pass From a22cbd3bfce1adb41b270a61d4379983c98daa98 Mon Sep 17 00:00:00 2001 From: Thomas Kunambi Date: Tue, 22 Jun 2021 19:51:35 +0200 Subject: [PATCH 14/31] Update currencies.json Replace Bitcoin symbol with unicode --- forex_python/raw_data/currencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/raw_data/currencies.json b/forex_python/raw_data/currencies.json index ed57ae3..4adce67 100644 --- a/forex_python/raw_data/currencies.json +++ b/forex_python/raw_data/currencies.json @@ -20,7 +20,7 @@ {"cc":"BOB","symbol":"Bs.","name":"Bolivian boliviano"}, {"cc":"BRL","symbol":"R$","name":"Brazilian real"}, {"cc":"BSD","symbol":"B$","name":"Bahamian dollar"}, - {"cc":"BTC","symbol":"₿","name":"Bitcoin"}, + {"cc":"BTC","symbol":"\u20bf","name":"Bitcoin"}, {"cc":"BTN","symbol":"Nu.","name":"Bhutanese ngultrum"}, {"cc":"BWP","symbol":"P","name":"Botswana pula"}, {"cc":"BYR","symbol":"Br","name":"Belarusian ruble"}, From 1c07f0a728dd9c1f50e91f704403ab0167f0c4a2 Mon Sep 17 00:00:00 2001 From: Thomas Kunambi Date: Tue, 22 Jun 2021 19:56:41 +0200 Subject: [PATCH 15/31] Create currencies.json Replace Bitcoin symbol with unicode --- forex_python/raw_data/currencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/raw_data/currencies.json b/forex_python/raw_data/currencies.json index ed57ae3..4adce67 100644 --- a/forex_python/raw_data/currencies.json +++ b/forex_python/raw_data/currencies.json @@ -20,7 +20,7 @@ {"cc":"BOB","symbol":"Bs.","name":"Bolivian boliviano"}, {"cc":"BRL","symbol":"R$","name":"Brazilian real"}, {"cc":"BSD","symbol":"B$","name":"Bahamian dollar"}, - {"cc":"BTC","symbol":"₿","name":"Bitcoin"}, + {"cc":"BTC","symbol":"\u20bf","name":"Bitcoin"}, {"cc":"BTN","symbol":"Nu.","name":"Bhutanese ngultrum"}, {"cc":"BWP","symbol":"P","name":"Botswana pula"}, {"cc":"BYR","symbol":"Br","name":"Belarusian ruble"}, From 8c49e9c05481cc171b29cf6db1d92496ec55e3d8 Mon Sep 17 00:00:00 2001 From: Timmeh Date: Fri, 9 Jul 2021 14:22:06 +0200 Subject: [PATCH 16/31] Add missing currencies and correct some ISO 4217 currency codes --- forex_python/raw_data/currencies.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/forex_python/raw_data/currencies.json b/forex_python/raw_data/currencies.json index 4adce67..335116c 100644 --- a/forex_python/raw_data/currencies.json +++ b/forex_python/raw_data/currencies.json @@ -99,7 +99,7 @@ {"cc":"MWK","symbol":"MK","name":"Malawian kwacha"}, {"cc":"MXN","symbol":"$","name":"Mexican peso"}, {"cc":"MYR","symbol":"RM","name":"Malaysian ringgit"}, - {"cc":"MZM","symbol":"MTn","name":"Mozambican metical"}, + {"cc":"MZN","symbol":"MT","name":"Mozambican metical"}, {"cc":"NAD","symbol":"N$","name":"Namibian dollar"}, {"cc":"NGN","symbol":"\u20a6","name":"Nigerian naira"}, {"cc":"NIO","symbol":"C$","name":"Nicaraguan c\u00f3rdoba"}, @@ -118,6 +118,7 @@ {"cc":"RON","symbol":"L","name":"Romanian leu"}, {"cc":"RSD","symbol":"din.","name":"Serbian dinar"}, {"cc":"RUB","symbol":"\u20bd","name":"Russian ruble"}, + {"cc":"RWF","symbol":"FRw","name":"Rwandan franc"}, {"cc":"SAR","symbol":"SR","name":"Saudi riyal"}, {"cc":"SBD","symbol":"SI$","name":"Solomon Islands dollar"}, {"cc":"SCR","symbol":"SR","name":"Seychellois rupee"}, @@ -128,12 +129,15 @@ {"cc":"SLL","symbol":"Le","name":"Sierra Leonean leone"}, {"cc":"SOS","symbol":"Sh.","name":"Somali shilling"}, {"cc":"SRD","symbol":"$","name":"Surinamese dollar"}, + {"cc":"STD","symbol":"Db","name":"São Tomé and Príncipe dobra"}, + {"cc":"STN","symbol":"Db","name":"São Tomé and Príncipe dobra"}, {"cc":"SYP","symbol":"LS","name":"Syrian pound"}, {"cc":"SZL","symbol":"E","name":"Swazi lilangeni"}, {"cc":"THB","symbol":"\u0e3f","name":"Thai baht"}, {"cc":"TJS","symbol":"TJS","name":"Tajikistani somoni"}, {"cc":"TMT","symbol":"m","name":"Turkmen manat"}, {"cc":"TND","symbol":"DT","name":"Tunisian dinar"}, + {"cc":"TOP","symbol":"T$","name":"Tongan Pa'anga"}, {"cc":"TRY","symbol":"TRY","name":"Turkish new lira"}, {"cc":"TTD","symbol":"TT$","name":"Trinidad and Tobago dollar"}, {"cc":"TWD","symbol":"NT$","name":"New Taiwan dollar"}, @@ -154,6 +158,6 @@ {"cc":"XPF","symbol":"F","name":"CFP franc"}, {"cc":"YER","symbol":"YER","name":"Yemeni rial"}, {"cc":"ZAR","symbol":"R","name":"South African rand"}, - {"cc":"ZMK","symbol":"ZK","name":"Zambian kwacha"}, + {"cc":"ZMW","symbol":"ZK","name":"Zambian kwacha"}, {"cc":"ZWR","symbol":"Z$","name":"Zimbabwean dollar"} ] From b533fdf2a1e6c3debacfcf186ce68cf4cfd47df4 Mon Sep 17 00:00:00 2001 From: Timmeh Date: Sun, 18 Jul 2021 14:44:26 +0200 Subject: [PATCH 17/31] Fix USD symbol --- forex_python/raw_data/currencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/raw_data/currencies.json b/forex_python/raw_data/currencies.json index 335116c..28baca0 100644 --- a/forex_python/raw_data/currencies.json +++ b/forex_python/raw_data/currencies.json @@ -144,7 +144,7 @@ {"cc":"TZS","symbol":"TZS","name":"Tanzanian shilling"}, {"cc":"UAH","symbol":"UAH","name":"Ukrainian hryvnia"}, {"cc":"UGX","symbol":"USh","name":"Ugandan shilling"}, - {"cc":"USD","symbol":"US$","name":"United States dollar"}, + {"cc":"USD","symbol":"$","name":"United States dollar"}, {"cc":"UYU","symbol":"$U","name":"Uruguayan peso"}, {"cc":"UZS","symbol":"UZS","name":"Uzbekistani som"}, {"cc":"VEB","symbol":"Bs","name":"Venezuelan bolivar"}, From 4aa3095787d2b1054dfe89ff089302e6206abe46 Mon Sep 17 00:00:00 2001 From: Abhijeet Date: Thu, 2 Sep 2021 11:37:24 +0530 Subject: [PATCH 18/31] forex_python.converter.RatesNotAvailableError: Currency Rates Source Not Ready issue fixed --- forex_python/converter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index 567e9f8..bf465d0 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -37,9 +37,8 @@ def _decode_rates(self, response, use_decimal=False, date_str=None): decoded_data = json.loads(response.text, use_decimal=True) else: decoded_data = response.json() - if (date_str and date_str != 'latest' - and date_str != decoded_data.get('date')): - raise RatesNotAvailableError("Currency Rates Source Not Ready") + # if (date_str and date_str != 'latest' and date_str != decoded_data.get('date')): + # raise RatesNotAvailableError("Currency Rates Source Not Ready") return decoded_data.get('rates', {}) def _get_decoded_rate( From 4e826b341b6d3f53e5b2e9b61722bc2781fef987 Mon Sep 17 00:00:00 2001 From: Robbie-Palmer <8760191+Robbie-Palmer@users.noreply.github.com> Date: Sat, 6 Nov 2021 21:37:38 +0000 Subject: [PATCH 19/31] Format converter.py --- forex_python/converter.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index bf465d0..c652a2c 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -1,7 +1,8 @@ import os from decimal import Decimal -import simplejson as json + import requests +import simplejson as json class RatesNotAvailableError(Exception): @@ -45,7 +46,7 @@ def _get_decoded_rate( self, response, dest_cur, use_decimal=False, date_str=None): return self._decode_rates( response, use_decimal=use_decimal, date_str=date_str).get( - dest_cur, None) + dest_cur, None) class CurrencyRates(Common): @@ -102,7 +103,8 @@ def convert(self, base_cur, dest_cur, amount, date_obj=None): converted_amount = rate * amount return converted_amount except TypeError: - raise DecimalFloatMismatchError("convert requires amount parameter is of type Decimal when force_decimal=True") + raise DecimalFloatMismatchError( + "convert requires amount parameter is of type Decimal when force_decimal=True") raise RatesNotAvailableError("Currency Rates Source Not Ready") @@ -120,7 +122,7 @@ def __init__(self): def _get_data(self, currency_code): file_path = os.path.dirname(os.path.abspath(__file__)) - with open(file_path+'/raw_data/currencies.json') as f: + with open(file_path + '/raw_data/currencies.json') as f: currency_data = json.loads(f.read()) currency_dict = next((item for item in currency_data if item["cc"] == currency_code), None) return currency_dict @@ -153,7 +155,6 @@ def get_currency_code_from_symbol(self, symbol): _CURRENCY_CODES = CurrencyCodes() - get_symbol = _CURRENCY_CODES.get_symbol get_currency_name = _CURRENCY_CODES.get_currency_name get_currency_code_from_symbol = _CURRENCY_CODES.get_currency_code_from_symbol From 7e0bb8094729b12e2d8b353d1b7cf3d1ea054471 Mon Sep 17 00:00:00 2001 From: Robbie-Palmer <8760191+Robbie-Palmer@users.noreply.github.com> Date: Sat, 6 Nov 2021 21:43:00 +0000 Subject: [PATCH 20/31] Lazy load currency data from json file Removing duplicate code, and preventing redundant disk reads --- forex_python/converter.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index c652a2c..390a11a 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -118,20 +118,22 @@ def convert(self, base_cur, dest_cur, amount, date_obj=None): class CurrencyCodes: def __init__(self): - pass + self.__currency_data = None + + @property + def _currency_data(self): + if self.__currency_data is None: + file_path = os.path.dirname(os.path.abspath(__file__)) + with open(file_path + '/raw_data/currencies.json') as f: + self.__currency_data = json.loads(f.read()) + return self.__currency_data def _get_data(self, currency_code): - file_path = os.path.dirname(os.path.abspath(__file__)) - with open(file_path + '/raw_data/currencies.json') as f: - currency_data = json.loads(f.read()) - currency_dict = next((item for item in currency_data if item["cc"] == currency_code), None) + currency_dict = next((item for item in self._currency_data if item["cc"] == currency_code), None) return currency_dict def _get_data_from_symbol(self, symbol): - file_path = os.path.dirname(os.path.abspath(__file__)) - with open(file_path + '/raw_data/currencies.json') as f: - currency_data = json.loads(f.read()) - currency_dict = next((item for item in currency_data if item["symbol"] == symbol), None) + currency_dict = next((item for item in self._currency_data if item["symbol"] == symbol), None) return currency_dict def get_symbol(self, currency_code): From a40f1a4845ea460937d85f29aca86afd26b27d45 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Fri, 15 Jul 2022 08:17:20 +1000 Subject: [PATCH 21/31] docs: fix simple typo, lates -> latest There is a small typo in docs/source/usage.rst. Should read `latest` rather than `lates`. --- docs/source/usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 779e478..15e39a2 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -76,7 +76,7 @@ Bitcoin Prices: >>> b.convert_to_btc_on(5000, 'USD', date_obj) # convert_to_btc_on(5000, 'USD', date_obj) 11.028325150316071 -5. Convert Bitcoins to valid currency amount based on lates price:: +5. Convert Bitcoins to valid currency amount based on latest price:: >>> b.convert_btc_to_cur(1.25, 'USD') # convert_btc_to_cur(1.25, 'USD') 668.1012499999999 From d50b60cb291152bfb3f7ab409febcbf8dec13552 Mon Sep 17 00:00:00 2001 From: Big Head <52704158+internall@users.noreply.github.com> Date: Sun, 31 Jul 2022 22:20:38 +0200 Subject: [PATCH 22/31] remove & update obsolete link precedent link: https://www.coindesk.com/tag/api/ leads to /error/404, therefore it is preferable to change it to the main page of coindesk --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6bc71d2..ddb30cd 100644 --- a/README.rst +++ b/README.rst @@ -40,7 +40,7 @@ The rates are updated daily 3PM CET. BitCoin Price Source: --------------------- -Bitcoin prices calculated every minute. For more information visit [CoinDesk API](http://www.coindesk.com/api/). +Bitcoin prices calculated every minute. For more information visit [CoinDesk](http://www.coindesk.com). Installation -------------- From 30b10cc8524ac25200b442afd80d5596239509f9 Mon Sep 17 00:00:00 2001 From: "Mark E. Fuller" Date: Sun, 5 Feb 2023 22:09:25 +0200 Subject: [PATCH 23/31] typos and grammar --- docs/source/index.rst | 12 ++++++------ docs/source/usage.rst | 14 +++++++------- forex_python/bitcoin.py | 22 +++++++++++----------- forex_python/converter.py | 2 +- tests/test_bitcoin.py | 14 +++++++------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index c009d5f..6d42f63 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,17 +1,17 @@ forex-python ============ -Free Foreign exchange rates, bitcoin prices and currency conversion. +Free foreign exchange rates, Bitcoin prices and currency conversion. Features: --------- - List all currency rates. -- BitCoin price for all currencies. -- Converting amount to BitCoins. +- Bitcoin price for all currencies. +- Converting amount to BitCoin. - Get historical rates for any day since 1999. -- Conversion rate for one currency(ex; USD to INR). -- Convert amount from one currency to other.('USD 10$' to INR) -- Currency Symbols +- Conversion rate for one currency (e.g. USD to INR). +- Convert amount from one currency to another (e.g. 'USD $10' to INR) +- Currency symbols - Currency names Contents: diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 15e39a2..d62607f 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -66,21 +66,21 @@ Bitcoin Prices: >>> b.get_previous_price('USD', date_obj) # get_previous_price('USD', date_obj) 453.378 -3. Convert Amout to bitcoins:: +3. Convert Amount to Bitcoin:: >>> b.convert_to_btc(5000, 'USD') # convert_to_btc(5000, 'USD') 9.36345369116708 -4. Convert Amount to bitcoins based on previous date prices:: +4. Convert Amount to Bitcoin based on previous date prices:: >>> date_obj datetime.datetime(2016, 5, 18, 19, 39, 36, 815417) >>> b.convert_to_btc_on(5000, 'USD', date_obj) # convert_to_btc_on(5000, 'USD', date_obj) 11.028325150316071 -5. Convert Bitcoins to valid currency amount based on latest price:: +5. Convert Bitcoin to valid currency amount based on latest price:: >>> b.convert_btc_to_cur(1.25, 'USD') # convert_btc_to_cur(1.25, 'USD') 668.1012499999999 -6. Convert Bitcoins to valid currency amount based on previous date price:: +6. Convert Bitcoin to valid currency amount based on previous date price:: >>> date_obj datetime.datetime(2016, 5, 18, 19, 39, 36, 815417) >>> b.convert_btc_to_cur_on(1.25, 'EUR', date_obj) @@ -106,7 +106,7 @@ Bitcoin Prices: Currency Symbols & Codes ------------------------- -1. Get Currency symbol Using currency code:: +1. Get currency symbol using currency code:: >>> from forex_python.converter import CurrencyCodes >>> c = CurrencyCodes() >>> c.get_symbol('GBP') @@ -116,8 +116,8 @@ Currency Symbols & Codes >>> print c.get_symbol('EUR') € -2. Get Currency Name using currency code:: +2. Get currency name using currency code:: >>> c.get_currency_name('EUR') u'European Euro' >>> c.get_currency_name('INR') - u'Indian rupee' + u'Indian Rupee' diff --git a/forex_python/bitcoin.py b/forex_python/bitcoin.py index 6ccd226..b699a4d 100644 --- a/forex_python/bitcoin.py +++ b/forex_python/bitcoin.py @@ -6,7 +6,7 @@ class BtcConverter(object): """ - Get bit coin rates and convertion + Get Bitcoin rates and conversion """ def __init__(self, force_decimal=False): self._force_decimal = force_decimal @@ -20,7 +20,7 @@ def _decode_rates(self, response, use_decimal=False): def get_latest_price(self, currency): """ - Get Lates price of one bitcoin to valid Currency 1BTC => X USD + Get latest price of one Bitcoin to valid currency 1BTC => X USD """ url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json'.format(currency) response = requests.get(url) @@ -34,7 +34,7 @@ def get_latest_price(self, currency): def get_previous_price(self, currency, date_obj): """ - Get Price for one bit coin on given date + Get price for one Bitcoin on given date """ start = date_obj.strftime('%Y-%m-%d') end = date_obj.strftime('%Y-%m-%d') @@ -55,7 +55,7 @@ def get_previous_price(self, currency, date_obj): def get_previous_price_list(self, currency, start_date, end_date): """ - Get List of prices between two dates + Get list of Bitcoin prices between two dates """ start = start_date.strftime('%Y-%m-%d') end = end_date.strftime('%Y-%m-%d') @@ -74,7 +74,7 @@ def get_previous_price_list(self, currency, start_date, end_date): def convert_to_btc(self, amount, currency): """ - Convert X amount to Bit Coins + Convert X amount to Bitcoin """ if isinstance(amount, Decimal): use_decimal = True @@ -98,7 +98,7 @@ def convert_to_btc(self, amount, currency): def convert_btc_to_cur(self, coins, currency): """ - Convert X bit coins to valid currency amount + Convert X Bitcoin to valid currency amount """ if isinstance(coins, Decimal): use_decimal = True @@ -122,7 +122,7 @@ def convert_btc_to_cur(self, coins, currency): def convert_to_btc_on(self, amount, currency, date_obj): """ - Convert X amount to BTC based on given date rate + Convert X amount to Bitcoin based on a given date's rate """ if isinstance(amount, Decimal): use_decimal = True @@ -149,11 +149,11 @@ def convert_to_btc_on(self, amount, currency, date_obj): return converted_btc except TypeError: raise DecimalFloatMismatchError("convert_to_btc_on requires amount parameter is of type Decimal when force_decimal=True") - raise RatesNotAvailableError("BitCoin Rates Source Not Ready For Given Date") + raise RatesNotAvailableError("Bitcoin rates source not ready for given date") def convert_btc_to_cur_on(self, coins, currency, date_obj): """ - Convert X BTC to valid currency amount based on given date + Convert X Bitcoin to valid currency amount based on given's date rate """ if isinstance(coins, Decimal): use_decimal = True @@ -180,11 +180,11 @@ def convert_btc_to_cur_on(self, coins, currency, date_obj): return converted_btc except TypeError: raise DecimalFloatMismatchError("convert_btc_to_cur_on requires amount parameter is of type Decimal when force_decimal=True") - raise RatesNotAvailableError("BitCoin Rates Source Not Ready For Given Date") + raise RatesNotAvailableError("Bitcoin rates source not ready for given date") def get_symbol(self): """ - Here is Unicode symbol for bitcoin + Here is the Unicode symbol for Bitcoin: """ return "\u0E3F" diff --git a/forex_python/converter.py b/forex_python/converter.py index 390a11a..4655b7b 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -7,7 +7,7 @@ class RatesNotAvailableError(Exception): """ - Custome Exception when https://theforexapi.com is Down and not available for currency rates + Custom exception when https://theforexapi.com is down and not available for currency rates """ pass diff --git a/tests/test_bitcoin.py b/tests/test_bitcoin.py index a747c8c..f2eccfd 100644 --- a/tests/test_bitcoin.py +++ b/tests/test_bitcoin.py @@ -55,7 +55,7 @@ def test_previous_price_list_with_invalid_currency(self): class TestConvertBtc(TestCase): """ - Test Converting amount to Bit coins + Test converting amount to Bitcoin """ def test_convet_to_btc_with_valid_currency(self): coins = convert_to_btc(250, 'USD') @@ -67,7 +67,7 @@ def test_convet_to_btc_with_invalid_currency(self): class TestConvertBtcToCur(TestCase): """ - Convert Bit Coins to Valid Currency amount + Convert Bitcoin to valid currency amount """ def test_convert_btc_to_cur_valid_currency(self): amount = convert_btc_to_cur(2, 'USD') @@ -79,7 +79,7 @@ def test_convert_btc_to_cur_invalid_currency(self): class TestConvertToBtcOn(TestCase): """ - Convert To bit coin based on previous dates + Convert to Bitcoin based on previous date """ def test_convert_to_btc_on_with_valid_currency(self): date_obj = datetime.datetime.today() - datetime.timedelta(days=15) @@ -93,7 +93,7 @@ def test_convert_to_btc_on_with_invalid_currency(self): class TestConvertBtcToCurOn(TestCase): """ - Convert BitCoins to valid Currency + Convert Bitcoin to valid currency """ def test_convert_to_btc_on_with_valid_currency(self): date_obj = datetime.datetime.today() - datetime.timedelta(days=15) @@ -107,7 +107,7 @@ def test_convert_to_btc_on_with_invalid_currency(self): class TestBitCoinSymbol(TestCase): """ - Bit Coin symbol + Bitcoin symbol """ def test_bitcoin_symbol(self): self.assertEqual(get_btc_symbol(), "\u0E3F") @@ -218,11 +218,11 @@ def test_previous_price_list_with_invalid_currency(self): self.assertFalse(price_list) self.assertEqual(type(price_list), dict) - def test_convet_to_btc_with_valid_currency(self): + def test_convert_to_btc_with_valid_currency(self): coins = self.b.convert_to_btc(Decimal('250'), 'USD') self.assertEqual(type(coins), Decimal) - def test_convet_to_btc_with_invalid_currency(self): + def test_convert_to_btc_with_invalid_currency(self): self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc, Decimal('250'), 'XYZ') def test_convert_btc_to_cur_valid_currency(self): From 803a1114da24610c8c5bd31a0bc4eef37c5d9b06 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Mon, 6 Feb 2023 07:30:35 +0530 Subject: [PATCH 24/31] Update README.rst --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index ddb30cd..10f8ea5 100644 --- a/README.rst +++ b/README.rst @@ -21,6 +21,8 @@ Forex Python is a Free Foreign exchange rates and currency conversion. **Note: Install latest forex-python==1.6 to avoid RatesNotAvailableError** +[![RunCode](https://runcode-app-public.s3.amazonaws.com/images/dark_btn.png)](https://runcode.io) + Features of Forex Python: --------- - List all currency rates. From 696c54983207258cf9717693667d0bf3869bd24e Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Mon, 6 Feb 2023 07:32:08 +0530 Subject: [PATCH 25/31] Update README.rst --- README.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 10f8ea5..4cec232 100644 --- a/README.rst +++ b/README.rst @@ -14,14 +14,17 @@ forex-python :alt: Code Health .. image:: https://img.shields.io/badge/python-2.7%2C%203.3%2C%203.4%2C%203.5-blue.svg - :target: https://pypi.python.org/pypi/forex-python - :alt: pypi + :target: https://pypi.python.org/pypi/forex-python + :alt: pypi Forex Python is a Free Foreign exchange rates and currency conversion. **Note: Install latest forex-python==1.6 to avoid RatesNotAvailableError** -[![RunCode](https://runcode-app-public.s3.amazonaws.com/images/dark_btn.png)](https://runcode.io) +.. image:: https://runcode-app-public.s3.amazonaws.com/images/dark_btn.png + :target: https://runcode.io + :alt: RunCode + Features of Forex Python: --------- From b1915c0af51cf8fd5e0d9db9c9734070bee7046a Mon Sep 17 00:00:00 2001 From: juliocesar126 <114194657+juliocesar126@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:58:56 -0300 Subject: [PATCH 26/31] Create Julio9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Julio cesar moro em São --- Julio9 | 1 + 1 file changed, 1 insertion(+) create mode 100644 Julio9 diff --git a/Julio9 b/Julio9 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Julio9 @@ -0,0 +1 @@ + From caae9e000ac98668b669db9506efc0d0ff645c14 Mon Sep 17 00:00:00 2001 From: juliocesar126 <114194657+juliocesar126@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:59:55 -0300 Subject: [PATCH 27/31] Delete Julio9 N --- Julio9 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Julio9 diff --git a/Julio9 b/Julio9 deleted file mode 100644 index 8b13789..0000000 --- a/Julio9 +++ /dev/null @@ -1 +0,0 @@ - From 5d85735e009305436e96ed42ca9dd0817ce9570c Mon Sep 17 00:00:00 2001 From: Tauhid Ahmed <87439534+Tauhid-Ahmed8009@users.noreply.github.com> Date: Mon, 4 Sep 2023 00:26:49 +0600 Subject: [PATCH 28/31] Update converter.py added utf-8 encoding when opening curriencies.json. otherwise exception type: unicodedecodeerror exception value: 'ascii' codec can't decode byte 0xc3 in position 7400: ordinal not in range(128) in ubuntu server --- forex_python/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index 4655b7b..695fe8c 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -124,7 +124,7 @@ def __init__(self): def _currency_data(self): if self.__currency_data is None: file_path = os.path.dirname(os.path.abspath(__file__)) - with open(file_path + '/raw_data/currencies.json') as f: + with open(file_path + '/raw_data/currencies.json', encoding="utf-8") as f: self.__currency_data = json.loads(f.read()) return self.__currency_data From 679c09648d787d280980b5a646c1b835ff0883d5 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Wed, 21 May 2025 23:22:25 +0530 Subject: [PATCH 29/31] Update converter.py --- forex_python/converter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forex_python/converter.py b/forex_python/converter.py index 695fe8c..17345c9 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -7,7 +7,7 @@ class RatesNotAvailableError(Exception): """ - Custom exception when https://theforexapi.com is down and not available for currency rates + Custom exception when https://theratesapi.com is down and not available for currency rates """ pass @@ -25,7 +25,7 @@ def __init__(self, force_decimal=False): self._force_decimal = force_decimal def _source_url(self): - return "https://theforexapi.com/api/" + return "https://theratesapi.com/api/" def _get_date_string(self, date_obj): if date_obj is None: From 40dfe0f200c529a6b1f7505d3cbbb47d0d7c9a3d Mon Sep 17 00:00:00 2001 From: ashwin Date: Thu, 22 May 2025 09:26:03 +0530 Subject: [PATCH 30/31] Update API references and version numbers in documentation and setup files --- README.rst | 2 +- docs/source/conf.py | 4 +-- docs/source/currencysource.rst | 4 +-- setup.py | 54 ++++++++++++++++++---------------- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/README.rst b/README.rst index 4cec232..61029c2 100644 --- a/README.rst +++ b/README.rst @@ -40,7 +40,7 @@ Features of Forex Python: Currency Source: ----------------- -https://theforexapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. +https://theratesapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. The rates are updated daily 3PM CET. BitCoin Price Source: diff --git a/docs/source/conf.py b/docs/source/conf.py index 4e7c981..decf5a9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -59,9 +59,9 @@ # built documents. # # The short X.Y version. -version = u'1.6' +version = u'1.9' # The full version, including alpha/beta/rc tags. -release = u'1.6' +release = u'1.9' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/currencysource.rst b/docs/source/currencysource.rst index 170281a..1c6dbf9 100644 --- a/docs/source/currencysource.rst +++ b/docs/source/currencysource.rst @@ -1,9 +1,9 @@ currency source =============== -https://theforexapi.com +https://theratesapi.com -------- -https://theforexapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. The rates are updated daily 3PM CET. +https://theratesapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. The rates are updated daily 3PM CET. List of Supported Currency codes. --------------------------------- diff --git a/setup.py b/setup.py index de66932..dd6dae6 100644 --- a/setup.py +++ b/setup.py @@ -2,47 +2,51 @@ import os from setuptools import setup, find_packages -VERSION = '1.6' -long_description_text = """Forex Python is a Free Foreign exchange rates and currency conversion. -Features: -List all currency rates. -BitCoin price for all curuncies. -Converting amount to BitCoins. -Get historical rates for any day since 1999. -Conversion rate for one currency(ex; USD to INR). -Convert amount from one currency to other.('USD 10$' to INR). -Currency symbols. -Currency names. +# 1) Bump this version each release: +VERSION = '1.9' -Documentation: http://forex-python.readthedocs.io/en/latest/usage.html -GitHub: https://github.com/MicroPyramid/forex-python - -""" +# 2) Pull your README.md in as long_description: +here = os.path.abspath(os.path.dirname(__file__)) +with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() setup( name='forex-python', version=VERSION, author='Micro Pyramid Informatic Pvt. Ltd.', author_email='hello@micropyramid.com', + description='Free foreign exchange rates and currency conversion.', + long_description=long_description, + long_description_content_type='text/markdown', # so PyPI renders your README properly url='https://github.com/MicroPyramid/forex-python', - description='Foreign exchange rates and currency conversion.', - long_description=long_description_text, - packages=find_packages(exclude=['tests', 'tests.*']), + packages=find_packages(exclude=['tests*']), include_package_data=True, install_requires=[ - 'requests', - 'simplejson', + 'requests>=2.0', + 'simplejson>=3.0', ], + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4', classifiers=[ + # audience 'Intended Audience :: Developers', - 'Operating System :: OS Independent', + 'Topic :: Software Development :: Internationalization', + # license 'License :: OSI Approved :: MIT License', + # OS + 'Operating System :: OS Independent', + # languages 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Topic :: Software Development :: Internationalization', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], + project_urls={ # these show up as “Project Links” on PyPI + 'Documentation': 'https://forex-python.readthedocs.io/', + 'Source': 'https://github.com/MicroPyramid/forex-python', + 'Tracker': 'https://github.com/MicroPyramid/forex-python/issues', + }, ) From 6433f0a2c5b7652e495ef0134b940ae5a6a68cdb Mon Sep 17 00:00:00 2001 From: ashwin Date: Thu, 22 May 2025 10:23:40 +0530 Subject: [PATCH 31/31] Add README.md and update version to 1.9.2 in setup.py and conf.py; enhance rate handling in converter.py --- README.md | 108 +++++++++++++++++++++++++ README.rst | 162 -------------------------------------- docs/source/conf.py | 4 +- forex_python/converter.py | 3 + setup.py | 2 +- 5 files changed, 114 insertions(+), 165 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/README.md b/README.md new file mode 100644 index 0000000..298726b --- /dev/null +++ b/README.md @@ -0,0 +1,108 @@ +# forex-python + +[![travis-ci](https://travis-ci.org/MicroPyramid/forex-python.svg?branch=master)](https://travis-ci.org/MicroPyramid/forex-python) +[![coveralls](https://coveralls.io/repos/github/MicroPyramid/forex-python/badge.svg?branch=master)](https://coveralls.io/github/MicroPyramid/forex-python?branch=master) +[![Code Health](https://landscape.io/github/MicroPyramid/forex-python/master/landscape.svg?style=flat)](https://landscape.io/github/MicroPyramid/forex-python/master) +[![pypi](https://img.shields.io/badge/python-3.6%2B-blue.svg)](https://pypi.python.org/pypi/forex-python) + +**Forex Python** is a free library for foreign exchange rates and currency conversion, supporting Python 3.6 and above. + +> **Note:** Install the latest version (`forex-python>=1.6`) to avoid `RatesNotAvailableError`. + +## Features + +- List all currency rates +- Bitcoin price for all currencies +- Convert amounts to and from Bitcoin +- Get historical rates (since 1999) +- Currency conversion (e.g., USD to INR) +- Currency symbols and names + +## Currency Source + +[theratesapi.com](https://theratesapi.com) provides current and historical foreign exchange rates published by the European Central Bank. Rates are updated daily at 3PM CET. + +## Bitcoin Price Source + +Bitcoin prices are updated every minute. For more information, visit [CoinDesk](http://www.coindesk.com). + +## Installation + +Install via pip: +```bash +pip install forex-python +``` +Or clone the repository and install manually: +```bash +git clone https://github.com/MicroPyramid/forex-python.git +cd forex-python +python3 setup.py install +``` + +## Usage Examples + +**Initialize the class:** +```python +from forex_python.converter import CurrencyRates +c = CurrencyRates() +``` + +**List all latest currency rates for "USD":** +```python +c.get_rates('USD') +# Example output: {'INR': 83.12, 'EUR': 0.92, ...} +``` + +**Get conversion rate from USD to INR:** +```python +c.get_rate('USD', 'INR') +# Example output: 83.12 +``` + +**Convert amount from USD to INR:** +```python +c.convert('USD', 'INR', 10) +# Example output: 831.2 +``` + +**Force use of Decimal:** +```python +from decimal import Decimal +c = CurrencyRates(force_decimal=True) +c.convert('USD', 'INR', Decimal('10.45')) +# Example output: 868.75 +``` + +**Get latest Bitcoin price:** +```python +from forex_python.bitcoin import BtcConverter +b = BtcConverter() +b.get_latest_price('USD') +# Example output: 67000.0 +``` + +**Convert amount to Bitcoins:** +```python +b.convert_to_btc(400, 'USD') +# Example output: 0.00597 +``` + +**Get currency symbol using currency code:** +```python +from forex_python.converter import CurrencyCodes +codes = CurrencyCodes() +codes.get_symbol('GBP') +# Example output: '£' +``` + +For complete documentation, see the [forex-python docs](http://forex-python.readthedocs.org/en/latest/?badge=latest). + +--- + +## Support & Feedback + +- Found a bug? Please [open a GitHub issue](https://github.com/MicroPyramid/forex-python/issues). +- Need a new feature or custom development? [Contact us here](https://micropyramid.com/contact-us/). +- Visit our [Python Development Services](https://micropyramid.com/python-development-services/) page for more information. + +--- \ No newline at end of file diff --git a/README.rst b/README.rst deleted file mode 100644 index 61029c2..0000000 --- a/README.rst +++ /dev/null @@ -1,162 +0,0 @@ -forex-python -============ - -.. image:: https://travis-ci.org/MicroPyramid/forex-python.svg?branch=master - :target: https://travis-ci.org/MicroPyramid/forex-python - :alt: travis-ci - -.. image:: https://coveralls.io/repos/github/MicroPyramid/forex-python/badge.svg?branch=master - :target: https://coveralls.io/github/MicroPyramid/forex-python?branch=master - :alt: coveralls - -.. image:: https://landscape.io/github/MicroPyramid/forex-python/master/landscape.svg?style=flat - :target: https://landscape.io/github/MicroPyramid/forex-python/master - :alt: Code Health - -.. image:: https://img.shields.io/badge/python-2.7%2C%203.3%2C%203.4%2C%203.5-blue.svg - :target: https://pypi.python.org/pypi/forex-python - :alt: pypi - -Forex Python is a Free Foreign exchange rates and currency conversion. - -**Note: Install latest forex-python==1.6 to avoid RatesNotAvailableError** - -.. image:: https://runcode-app-public.s3.amazonaws.com/images/dark_btn.png - :target: https://runcode.io - :alt: RunCode - - -Features of Forex Python: ---------- -- List all currency rates. -- BitCoin price for all currencies. -- Converting amount to BitCoins. -- Get historical rates for any day since 1999. -- Conversion rate for one currency(ex; USD to INR). -- Convert amount from one currency to other.('USD 10$' to INR). -- Currency symbols. -- Currency names. - -Currency Source: ------------------ - -https://theratesapi.com is a free API for current and historical foreign exchange rates published by European Central Bank. -The rates are updated daily 3PM CET. - -BitCoin Price Source: ---------------------- -Bitcoin prices calculated every minute. For more information visit [CoinDesk](http://www.coindesk.com). - -Installation --------------- - -- Install using python package - - .. code-block:: python - - pip install forex-python - - Or directly cloning the repo: - - python setup.py install - -Usage Examples: ------------------- - -- Initialize class - - .. code-block:: python - - python - >>> from forex_python.converter import CurrencyRates - >>> c = CurrencyRates() - -- list all latest currency rates for "USD" - - .. code-block:: python - - python - >>> c.get_rates('USD') - {u'IDR': 13625.0, u'BGN': 1.7433, u'ILS': 3.8794, u'GBP': 0.68641, u'DKK': 6.6289, u'CAD': 1.3106, u'JPY': 110.36, u'HUF': 282.36, u'RON': 4.0162, u'MYR': 4.081, u'SEK': 8.3419, u'SGD': 1.3815, u'HKD': 7.7673, u'AUD': 1.3833, u'CHF': 0.99144, u'KRW': 1187.3, u'CNY': 6.5475, u'TRY': 2.9839, u'HRK': 6.6731, u'NZD': 1.4777, u'THB': 35.73, u'EUR': 0.89135, u'NOK': 8.3212, u'RUB': 66.774, u'INR': 67.473, u'MXN': 18.41, u'CZK': 24.089, u'BRL': 3.5473, u'PLN': 3.94, u'PHP': 46.775, u'ZAR': 15.747} - -- Get conversion rate from USD to INR - - .. code-block:: python - - python - >>> c.get_rate('USD', 'INR') - 67.473 - -- Convert amount from USD to INR - - .. code-block:: python - - python - >>> c.convert('USD', 'INR', 10) - 674.73 - -- Force use of Decimal - - .. code-block:: python - - python - >>> from forex_python.converter import CurrencyRates - >>> c = CurrencyRates(force_decimal=True) - >>> c.convert('USD', 'INR', Decimal('10.45')) - 705.09 - >>> c.convert('USD', 'INR', 10) - DecimalFloatMismatchError: convert requires amount parameter is of type Decimal when use_decimal=True - -- Detect use of Decimal - - .. code-block:: python - - python - >>> from forex_python.converter import CurrencyRates - >>> c = CurrencyRates() - >>> c.convert('USD', 'INR', Decimal('10.45')) - 705.09 - >>> c.convert('USD', 'INR', 10) - 674.73 - -- Get latest Bitcoin price. - - .. code-block:: python - - python - >>> from forex_python.bitcoin import BtcConverter - >>> b = BtcConverter() # force_decimal=True to get Decimal rates - >>> b.get_latest_price('USD') - 533.913 - - -- Convert Amount to Bitcoins based on latest exchange price. - - .. code-block:: python - - python - >>> b.convert_to_btc(400, 'USD') - 0.7492699301118473 - - -- Get currency symbol using currency code - - .. code-block:: python - - python - >>> from forex_python.converter import CurrencyCodes - >>> c = CurrencyCodes() - >>> print c.get_symbol('GBP') - £ - - -You can view the complete `Documentation Here`_ - -Visit our Python Development page `Here`_ - -We welcome your feedback and support, raise `github ticket`_ if you want to report a bug. Need new features? `Contact us here`_ - -.. _contact us here: https://micropyramid.com/contact-us/ -.. _github ticket: https://github.com/MicroPyramid/forex-python/issues -.. _Documentation Here: http://forex-python.readthedocs.org/en/latest/?badge=latest -.. _Here: https://micropyramid.com/python-development-services/ diff --git a/docs/source/conf.py b/docs/source/conf.py index decf5a9..bc49dd2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -59,9 +59,9 @@ # built documents. # # The short X.Y version. -version = u'1.9' +version = u'1.9.2' # The full version, including alpha/beta/rc tags. -release = u'1.9' +release = u'1.9.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/forex_python/converter.py b/forex_python/converter.py index 17345c9..d0c4f7a 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -99,6 +99,9 @@ def convert(self, base_cur, dest_cur, amount, date_obj=None): if not rate: raise RatesNotAvailableError("Currency {0} => {1} rate not available for Date {2}.".format( source_url, dest_cur, date_str)) + # Ensure rate is numeric + if isinstance(rate, str): + rate = Decimal(rate) if use_decimal else float(rate) try: converted_amount = rate * amount return converted_amount diff --git a/setup.py b/setup.py index dd6dae6..34dc559 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages # 1) Bump this version each release: -VERSION = '1.9' +VERSION = '1.9.2' # 2) Pull your README.md in as long_description: here = os.path.abspath(os.path.dirname(__file__))