From 2c352735de6d240e30c2e5539fa3aeedcab6b3da Mon Sep 17 00:00:00 2001 From: maheshschand Date: Fri, 9 Oct 2020 08:03:58 +0530 Subject: [PATCH 1/5] Add Currency Covertor --- Currency_Convertor/README.md | 12 +++++++++ Currency_Convertor/currency_convertor.py | 34 ++++++++++++++++++++++++ Currency_Convertor/requirements.txt | 1 + 3 files changed, 47 insertions(+) create mode 100644 Currency_Convertor/README.md create mode 100644 Currency_Convertor/currency_convertor.py create mode 100644 Currency_Convertor/requirements.txt diff --git a/Currency_Convertor/README.md b/Currency_Convertor/README.md new file mode 100644 index 000000000..13399b623 --- /dev/null +++ b/Currency_Convertor/README.md @@ -0,0 +1,12 @@ +# Currency Covertor +A python script used to convert the currency of one country to that of another country. + +## Modules Used +- requests + +## How to Use +1. Install necessary requirements using +``` pip install -r requirements.txt ``` +2. We are using fixer.io API for live conversion rates. Get your access key from [here](https://fixer.io/) +3. Replace **API_KEY** with your own API Key. +4. Input the countries you want to convert respectively and amount to be converted. diff --git a/Currency_Convertor/currency_convertor.py b/Currency_Convertor/currency_convertor.py new file mode 100644 index 000000000..dd7eda753 --- /dev/null +++ b/Currency_Convertor/currency_convertor.py @@ -0,0 +1,34 @@ +# Currency Convertor + +# Import necessary modules +import requests + +class Currency_Convertor: + rate = {} + def __init__(self, url): + data = requests.get(url).json() + + # Extracting rate from json + self.rate = data["rates"] + + # Conversion + def convert(self, from_country, to_country, amount): + initial = amount; + if from_country != 'EUR': + amount = amount / self.rates[from_country] + + # Precision to 2 decimal places + amount = round(amount * self.rate[to_country], 2) + print(f'{initial} {from_country} = {amount} {to_country}') + + +# Driver Code +if __name__ == "__main__": + # Replace API_KEY with your own API key from fixer.io + url = str.__add__('http://data.fixer.io/api/latest?access_key=', API_KEY) + cc = Currency_Convertor(url) + from_country = input("From: ") + to_country = input("To: ") + amount = int(input("Amount: ")) + + cc.convert(from_country, to_country, amount) diff --git a/Currency_Convertor/requirements.txt b/Currency_Convertor/requirements.txt new file mode 100644 index 000000000..f2293605c --- /dev/null +++ b/Currency_Convertor/requirements.txt @@ -0,0 +1 @@ +requests From 34125514a0304e0e7adb7026a644b8d98889904e Mon Sep 17 00:00:00 2001 From: maheshschand Date: Fri, 9 Oct 2020 08:07:01 +0530 Subject: [PATCH 2/5] Update README --- Currency_Convertor/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Currency_Convertor/README.md b/Currency_Convertor/README.md index 13399b623..c5de6cba9 100644 --- a/Currency_Convertor/README.md +++ b/Currency_Convertor/README.md @@ -6,7 +6,9 @@ A python script used to convert the currency of one country to that of another c ## How to Use 1. Install necessary requirements using -``` pip install -r requirements.txt ``` +```bash +pip install -r requirements.txt +``` 2. We are using fixer.io API for live conversion rates. Get your access key from [here](https://fixer.io/) 3. Replace **API_KEY** with your own API Key. 4. Input the countries you want to convert respectively and amount to be converted. From 8ed369f16c6356d94697673ba43ad5588a719a04 Mon Sep 17 00:00:00 2001 From: maheshschand Date: Fri, 9 Oct 2020 08:22:05 +0530 Subject: [PATCH 3/5] Update currency_convertor.py --- Currency_Convertor/currency_convertor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Currency_Convertor/currency_convertor.py b/Currency_Convertor/currency_convertor.py index dd7eda753..7b010bf32 100644 --- a/Currency_Convertor/currency_convertor.py +++ b/Currency_Convertor/currency_convertor.py @@ -3,17 +3,18 @@ # Import necessary modules import requests + class Currency_Convertor: rate = {} + def __init__(self, url): data = requests.get(url).json() - # Extracting rate from json self.rate = data["rates"] # Conversion def convert(self, from_country, to_country, amount): - initial = amount; + initial = amount if from_country != 'EUR': amount = amount / self.rates[from_country] From cf252ff0187d7b374566837580b5fd8140b100fd Mon Sep 17 00:00:00 2001 From: maheshschand Date: Fri, 9 Oct 2020 08:29:31 +0530 Subject: [PATCH 4/5] Update currency_convertor.py --- Currency_Convertor/currency_convertor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Currency_Convertor/currency_convertor.py b/Currency_Convertor/currency_convertor.py index 7b010bf32..5aca03068 100644 --- a/Currency_Convertor/currency_convertor.py +++ b/Currency_Convertor/currency_convertor.py @@ -1,10 +1,10 @@ -# Currency Convertor +# Currency Converter # Import necessary modules import requests -class Currency_Convertor: +class Currency_Converter: rate = {} def __init__(self, url): @@ -26,8 +26,8 @@ def convert(self, from_country, to_country, amount): # Driver Code if __name__ == "__main__": # Replace API_KEY with your own API key from fixer.io - url = str.__add__('http://data.fixer.io/api/latest?access_key=', API_KEY) - cc = Currency_Convertor(url) + url = 'http://data.fixer.io/api/latest?access_key=API_KEY' + cc = Currency_Converter(url) from_country = input("From: ") to_country = input("To: ") amount = int(input("Amount: ")) From 63921f067090a4e4c750e770419e84a7832d9dc7 Mon Sep 17 00:00:00 2001 From: maheshschand Date: Fri, 9 Oct 2020 08:32:19 +0530 Subject: [PATCH 5/5] Update spell check --- {Currency_Convertor => Currency_Converter}/README.md | 2 +- .../currency_converter.py | 0 {Currency_Convertor => Currency_Converter}/requirements.txt | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {Currency_Convertor => Currency_Converter}/README.md (95%) rename Currency_Convertor/currency_convertor.py => Currency_Converter/currency_converter.py (100%) rename {Currency_Convertor => Currency_Converter}/requirements.txt (100%) diff --git a/Currency_Convertor/README.md b/Currency_Converter/README.md similarity index 95% rename from Currency_Convertor/README.md rename to Currency_Converter/README.md index c5de6cba9..6821b14c1 100644 --- a/Currency_Convertor/README.md +++ b/Currency_Converter/README.md @@ -1,4 +1,4 @@ -# Currency Covertor +# Currency Converter A python script used to convert the currency of one country to that of another country. ## Modules Used diff --git a/Currency_Convertor/currency_convertor.py b/Currency_Converter/currency_converter.py similarity index 100% rename from Currency_Convertor/currency_convertor.py rename to Currency_Converter/currency_converter.py diff --git a/Currency_Convertor/requirements.txt b/Currency_Converter/requirements.txt similarity index 100% rename from Currency_Convertor/requirements.txt rename to Currency_Converter/requirements.txt