-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathcurr_conv.py
More file actions
27 lines (20 loc) · 784 Bytes
/
curr_conv.py
File metadata and controls
27 lines (20 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
class Currency_converter:
rates = {}
def __init__(self,url):
data=requests.get(url).json()
self.rates = data["rates"]
def convert(self , from_currency , to_currency , amount):
initial_amount = amount
if from_currency != 'EUR' :
amount = amount / self.rates[from_currency]
amount = round(amount * self.rates[to_currency] , 2)
print('{} {} = {} {}'.format(initial_amount , from_currency , amount , to_currency))
if __name__ == "__main__":
YOUR_ACCESS_KEY='GET YOUR ACCESS KEY FROM fixer.io'
url=str.__add__('http://data.fixer.io/api/latest?access_key=' , YOUR_ACCESS_KEY)
c=Currency_converter(url)
from = 'USD'
to = 'INR'
amount = 1
c.convert(from , to , amount)